我如何在d-languge中找到mongodb集合中的最后一个修改数据,并用find({“...”:“..”})进行筛选
我正在使用d语言进行编码,并试图提取最后一个从文档的阵列修改的文档,与d语言(在控制台不!!!!) 该查询是这样的:我如何在d-languge中找到mongodb集合中的最后一个修改数据,并用find({“...”:“..”})进行筛选
Collection ct = mongo.web.cell;
auto cell = ct.find({"room": 4 }).sort({'_id': -1 }).limit(1);
和通过配音给出的误差是
source/app.d(166,58): Error: found : when expecting ; following statement
source/app.d(166,61): Error: found } when expecting ; following statement
source/app.d(166,62): Error: found) instead of statement
当更改到达单元格数据插入的房间,未更新 我正在使用Visual Studio代码,最新版本
有什么想法?
我推断你使用mondo
,如果你看过库的文档和一些来自here和here的代码,以下是你需要做什么:
Mongo mongo = new Mongo("mongodb://yourhost");
Collection ct = mongo.web.cell;
auto q = new Query(); // create a new query object
q.conditions["room"] = 4; // specify the query condition
auto s = new BsonObject("_id", "-1"); // creat a new bson object
q.sorts(s.dup); // use sorts not sort
ct.find(q).each!writeln; // find the results
当您使用排序,你会使用std.algorithm.sorting而不是mondo的排序功能。
希望工程
嗨Quarashi它似乎一直工作到打印,它开始抱怨(运行3.0.6 mongodb):错误:没有属性'每个'类型'光标!(BsonObject)' –
从手册为3.0: db .users.find()。forEach(function(myDoc){print(“user:”+ myDoc.name);}); 也不管用 我知道我得到了mondo.collection –
@AndersS,'each'是一个标准的库迭代函数,只需导入'std.algorithm'并且你可以使用它,或者你可以返回结果然后使用foreach。 – Qurashi
'{“房间”:4}'是没有有效的语法,如果你想通过你需要使用'关联数组[“房间”:4]' – weltensturm
THKS但没't不是工作,而是得到这些错误,而不是: source/app.d(170,54):错误:未终止的字符常量 source/app.d(170,56):错误:在期望时发现ID;以下语句 source/app.d(170,58):错误:未终止的字符常量 source/app.d(170,60):Error:found:when expected;以下语句 source/app.d(170,63):Error:found} when expected;下面的语句 source/app.d(170,64):Error:found)而不是语句 –
而且如果我将行简化为find([“room”:4]);我得到这个错误mondo.Collection.find(T = BsonObject)(在查询query = Query.init中,在QueryFlags标志= QueryFlags.NONE中,在ReadPrefs readPrefs = null中) –