{"_id":"37389873",
"Date":{
"name":{"count":"7",
"user": "liyang",
}
}
}
像是資料庫中存的這個文檔,我想取count中的值7,只取數字7,不要文檔,改怎麼實現呢? ?
天蓬老师2017-04-24 16:02:54
db.xxx.findOne({"_id":"37389873"}, {"Date.name.count": 1}).Date.name.count
運行效果
~/tmp
▶ cat mmm.js
#!/usr/bin/env mongo
var db = connect('test');
db.xxx.drop();
db.xxx.insert({
"_id": "37389873",
"Date":{
"name":{"count":"7",
"user": "liyang",
}
}
});
print( db.xxx.findOne({"_id":"37389873"}, {"Date.name.count": 1}).Date.name.count );
~/tmp
▶ ./mmm.js
MongoDB shell version: 2.6.3
connecting to: test
connecting to: test
7
曾经蜡笔没有小新2017-04-24 16:02:54
spring 的 mongodb 外掛就可以滿足
BasicQuery query = new BasicQuery(query,fields);
query 是查詢條件
fields是要查詢的欄位