相关文章推荐
很酷的橡皮擦  ·  从Android到React ...·  1 年前    · 
英俊的哑铃  ·  python ...·  1 年前    · 
"_id" : ObjectId("57636c8e35defe029962107e"), "_class" : "com.bu2trip.ticket.model.Customer", "name" : "wang", "phone" : "18888888888", "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"})

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

对于到java客户端则为:

已MongoTemplate为例

        Criteria criatira = new Criteria();
		criatira.andOperator(Criteria.where("login_user.phone").is(110));
		Query query = new Query(criatira);
		Customer customer =  mongoTemplate.findOne(query,Customer.class);
        LoginUser loginUser = new LoginUser(xxxx);
        Criteria criatira = new Criteria();
		criatira.andOperator(Criteria.where("login_user").is(loginUser));
		Query query = new Query(criatira);
		Customer customer =  mongoTemplate.findOne(query,Customer.class);
				
MongoDB是一个面向文档的数据库系统。使用C++编写,不支持SQL,但有自己功能强大的查询语法。MongoDB使用BSON作为数据存储和传输的格式。BSON是一种类似JSON的二进制序列化文档,支持嵌套对象和数组。MongoDB很像MySQL,document对应MySQL的row,collection对应MySQL的table。MongoDB在Windows上的安装运行很方便。直接下载、解压,然后运行bin/mongod即可启动服务器,运行bin/mongo即可运行命令行客户端。官方网站:http://www.mongodb.org/downloads。下载对于版本,解压并抽取相关的bi
    "_id" : ObjectId("5c3c2ade8e40eb21b5ca69f4"),      "merid" : "201901091526",      "merorderno" : "1547447008",      "usersn" : NumberInt(42838),      "payments&quot