MongoDB C# 官方。列表查询问题并且总是旧值?
在使用 Id 和 Other 等两个条件进行查询期间,我没有明确提出问题。我使用存储库存储一些数据,例如 id、iso、value。我创建了一个索引(“_id”,“Iso”)来执行查询,但如果我仅使用一个像_id这样的条件,查询只会返回我的光标,但如果使用两个(_id,Iso)(注释代码),则不会返回任何内容.
是索引影响了响应还是查询方法失败了?
使用:v1.6.5和C#官方。
样本。
//Getting Data
public List<BsonObject> Get_object(string ID, string Iso)
{
using (var helper = BsonHelper.Create())
{
//helper.Db.Repository.EnsureIndex("_Id","Iso");
var query = Query.EQ("_Id", ID);
//if (!String.IsNullOrEmpty(Iso))
// query = Query.And(query, Query.EQ("Iso", Iso));
var cursor = helper.Db.Repository.FindAs<BsonObject>(query);
return cursor.ToList();
}
}
数据:
{
"_id": "2345019",
"Iso": "UK",
"Data": "Some data"
}
之后我使用 Update.Set() 方法更新了我的数据。我可以使用 MongoView 查看更改后的数据。新数据是正确的,但查询始终返回相同的旧值。为了查看这些值,我使用了一个最终可以缓存的页面,但是如果在末尾添加时间戳不会改变任何内容,则页面始终返回相同的旧数据。欢迎您提出宝贵意见,谢谢。
I have not clearly issue during query using two criterials like Id and Other. I use a Repository storing some data like id,iso,value. I have created an index("_id","Iso") to performs queries but queries are only returning my cursor if i use only one criterial like _id, but is returning nothing if a use two (_id, Iso) (commented code).
Are the index affecting the response or the query method are failing?
use :v1.6.5 and C# official.
Sample.
//Getting Data
public List<BsonObject> Get_object(string ID, string Iso)
{
using (var helper = BsonHelper.Create())
{
//helper.Db.Repository.EnsureIndex("_Id","Iso");
var query = Query.EQ("_Id", ID);
//if (!String.IsNullOrEmpty(Iso))
// query = Query.And(query, Query.EQ("Iso", Iso));
var cursor = helper.Db.Repository.FindAs<BsonObject>(query);
return cursor.ToList();
}
}
Data:
{
"_id": "2345019",
"Iso": "UK",
"Data": "Some data"
}
After that I have Updated my data using Update.Set() methods. I can see the changed data using MongoView. The new data are correct but the query is always returning the sames olds values. To see these values i use a page that can eventually cached, but if add a timestamp at end are not changing anything, page is always returning the same olds data. Your comments are welcome, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不记得 C# 驱动程序如何创建索引,但创建索引的 shell 命令是这样的:
注意“1”,它就像说“true”。
在您的代码中,您有:
也许应该是:
它也可能与您在“_Id”上创建索引并且实际的 id 字段称为“_id”这一事实有关... MongoDB 区分大小写。
快速浏览一下索引文档: http://www.mongodb.org/display/DOCS/索引
I do not recall offhand how the C# driver creates indexes, but the shell command for creating an index is like this:
Notice the '1' which is like saying 'true'.
In your code, you have:
Perhaps it should be:
It could also be related to the fact that you are creating indexes on "_Id" and the actual id field is called "_id" ... MongoDB is case sensitive.
Have a quick look through the index documentation: http://www.mongodb.org/display/DOCS/Indexes