这是我尝试的原始代码:
obj = {
    sentence:  "this is a sentece", 
    tags: [ "some", "indexing", "words"]     
}
和
findOne({tags: "words"}).name);
我使用TMongWire作为MongoDB for Delphi的包装器,我写了这个:
//var
//  d:IBSONDocument;
d:=BSON([
    'id',mongoObjectID,
    'sentence', 'this is a sentece',
    'tags','["some", "indexing", "words"]'
]);
FMongoWire.Insert(theCollection,d);
似乎上面的代码完成了工作
但是当我用'标签'查询时,它似乎对我不起作用
//var 
//q:TMongoWireQuery;
//qb:IBSONDocument 
qb:=BSON(['tags', '"words"']); //***
q:=TMongoWireQuery.Create(FMongoWire);
q.Query(mwx2Collection, qb); //***
如何用*星号写两行?
错误不在查询中,在字段创建中位.
在您编写它时,您将tags字段创建为字符串属性,而不是字符串数组.
d:=BSON([
    'id',mongoObjectID,
    'sentence', 'this is a sentece',
    'tags',VarArrayOf(['some', 'indexing', 'words'])
]);
FMongoWire.Insert(theCollection,d);
您必须调用VarArrayOf()以创建字符串数组.
编辑:介绍 VarArrayOf()