mongo查找方法

http://blog.csdn.net/canot/article/details/51699776

今天在项目中遇到了关于MongoDB嵌套查询,之前一直没有接触过,查询了相关资料后将结果记录下来。

MongoDB中的数据如下:

> db.customer.findOne()
{
    "_id" : ObjectId("57636c8e35defe029962107e"),
    "_class" : "com.bu2trip.ticket.model.Customer",
    "name" : "wang",
    "phone" : "18408221624",
    "gender" : 1,
    "birthday" : "1995-7-9",
    "passport" : "620524",
    "login_user" : {
        "_id" : ObjectId("5760e593086659036b77c124"),
        "email" : "test@bu2trip.com",
        "phone" : "110"
    }
}

如果要查询整个内嵌文档,查询语句如下:

db.customer.find({"login_user" : {"_id":ObjectId("5760e593086659036b77c124"), "email" : "test@bu2trip.com","phone" : "110"}})

 

在查询条件中必须写出以login_user为键的所有值。

只针对内嵌文档的特定键值进行查询如下:

 db.customer.findOne({"login_user.phone":"110"})

只需要匹配嵌套文档中的某个特定键值即可。

 

------------------

http://www.cnblogs.com/egger/archive/2013/06/14/3135847.html

2017.4.14  mongo 删除 db.getCollection('jobs').find({"start_time":{"$gt":"2017-04-14 21:50:00"}}) 大于这个时间的

posted @ 2017-04-14 20:18  foreverwith  阅读(210)  评论(0编辑  收藏  举报