mongodb自学习总结

1、mongodb中$elemMatch用法
功能:主要用户同级节点多属性过滤
a、以下这条语句会查出children.id="0730"的所有值
db.getCollection('regioncodes').find({"children":{"$elemMatch":{"children.id":"0730","children.text":"长沙"}}})

b、用elemMatch 多属性过滤后,只会找出满足id="0730"和text="岳阳"的值
db.getCollection('regioncodes').find({"children":{"$elemMatch":{"id":"0730","text":"岳阳"}}})

2、mongodb中怎么过滤不需要的字段或只展示需要的字段
说明:children.id=1表示展示,如果为0则隐藏不可见
db.getCollection('regioncodes').find({},{"children.id":1,"children.text":1})


猜你喜欢

转载自jiandequn.iteye.com/blog/2383878