RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
find详解-创新互联

find详解

创新互联建站-专业网站定制、快速模板网站建设、高性价比西充网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式西充网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖西充地区。费用合理售后完善,10余年实体公司更值得信赖。

find详解

find详解

等价查询某个数组:

db.getCollection("test").find(
    {
        tags: ["good","book","it","program"] 
    }
);

(//连顺序都要是存进去的顺序,不能变)

查询数组里的某一个值:

db.getCollection("test").find(
    {
        tags: "good"
    }
);

查询有四个元素的数组:

db.getCollection("test").find(
    {
        tags: {$size: 4}
    }
);

查询有或没有指定字段的,指定字段为null的情况:

db.getCollection("test").insert(
    [
        {_id: 2222, toy: null},
        {_id: 1112}
    ]
);
db.getCollection("test").find(
    {_id: 2222, toy: null}
);
db.getCollection("test").find(
    toy: null
); //报错
db.getCollection("test").find(
    {_id: 2222, toy: {$exists: true}}
); //找出来了当前这条
db.getCollection("test").find(
    {toy: {$exists: true}}
); //找出来了当前这条
db.getCollection("test").find(
    {toy: {$exists: false}}
); //找出所有没有toy这个字段的

查找返回值游标:

db.getCollection("test").find().forEach(function(item) {
    print(item.name, item.price, item.tags);
});

limit,skip方法:

db.getCollection("test").find().limit(1)
db.getCollection("test").find().skip(2)

$in的查询:

db.getCollection("test").find(
    {
        _id: {
            $in: {12, objectId("56970120abt538296thg0y6")}
        }
    }
); //查找_id等于12或objectId("56970120abt538296thg0y6")的文档记录

($in 用于不同文档指定同一个Key 进行或条件匹配, $or 可以指定多个Key 或条件匹配。)

区间查找:

db.getCollection("test").find(
    {
        price: {$gt: 3, $lt: 33}
    }
); //查询价格范围大于3小子33的值。可用于文档数值字段,也可以用于数组字段

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:find详解-创新互联
网页链接:http://scyingshan.cn/article/pchjd.html