加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在delphi中编写mongodb代码

发布时间:2020-12-15 09:36:26 所属栏目:大数据 来源:网络整理
导读:这是我尝试的原始代码: obj = { sentence: "this is a sentece",tags: [ "some","indexing","words"] } 和 findOne({tags: "words"}).name); 我使用TMongWire作为MongoDB for Delphi的包装器 我写了这个: //var// d:IBSONDocument;d:=BSON([ 'id',mongoObj
这是我尝试的原始代码:

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","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',VarArrayOf(['some','indexing','words'])
]);
FMongoWire.Insert(theCollection,d);

您必须调用VarArrayOf()来创建字符串数组.

编辑:介绍VarArrayOf()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读