0

在使用 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 查看更改的数据。新数据是正确的,但查询总是返回相同的旧值。要查看这些值,我使用最终可以缓存的页面,但如果在末尾添加时间戳不会改变任何内容,则页面总是返回相同的旧数据。欢迎您的意见,谢谢。

4

1 回答 1

0

我不记得 C# 驱动程序是如何创建索引的,但是用于创建索引的 shell 命令是这样的:

db.things.ensureIndex({j:1});

注意'1',这就像说'true'。

在您的代码中,您有:

helper.Db.Repository.EnsureIndex("_Id","Iso");

也许应该是:

helper.Db.Repository.EnsureIndex("_Id", 1);
helper.Db.Repository.EnsureIndex("Iso", 1);

这也可能与您在“_Id”上创建索引并且实际 id 字段称为“_id”的事实有关...... MongoDB 区分大小写。

Have a quick look through the index documentation: http://www.mongodb.org/display/DOCS/Indexes

于 2011-02-23T14:52:07.717 回答