zoukankan      html  css  js  c++  java
  • MongoDB(课时13 where条件过滤)

    3.4.2.8 条件过滤

    关系型数据库开发对于数据的筛选,想到的一定是where语句,MongoDB里面提供的是"$where"。

    范例:使用where进行数据的查询

    db.students.find({"$where" : "this.age>20"}).pretty()

    db.students.find("this.age>20").pretty()

    这里的this表示逐条的判断。

    对于“$where”是可以简化的,但是这类的操作是属于进行每一行的信息判断,实际上对于数据量较大的情况并不方便。实际上以上的代码严格来讲是属于编写一个操作的函数。

    db.students.find(function(){

      return this.age > 20;

    }).pretty()

    db.students.find({"$where" : function(){

      return this.age > 20;

    }}).pretty()

    以上只是查询了一个判断,如果要想实现多个条件的判断,那么就需要使用“and”连接。

    db.students.find({"$and" : [

      {"$where" : "this.age > 19"},

      {"$where" : "this.age < 21"}

    ]}).pretty()

    虽然这种形式的操作可以实现数据查询,但最大缺点是将MongoDB里面保存的BSON数据变为JavaScript的语法结构,这样的方式不方便使用数据库的索引机制。

  • 相关阅读:
    何为 ISAPI
    MacDown-The open source Markdown editor for OS X.
    Atom使用
    运维
    Perl
    Kaggle
    J2EE
    leetcode
    Tensorflow 学习笔记
    EXCEL公式及宏
  • 原文地址:https://www.cnblogs.com/keye/p/7967747.html
Copyright © 2011-2022 走看看