1. D:\MongoDB\Server\3.4\bin>mongo
  2. MongoDB shell version v3.4.16--g83c3022fe4
  3. connecting to: mongodb://127.0.0.1:27017
  4. MongoDB server version: 3.4.--g83c3022fe4
  5. Server has startup warnings:
  6. --04T11::41.286+ I CONTROL [initandlisten]
  7. --04T11::41.286+ I CONTROL [initandlisten] ** WARNING: Access control is not enabled fo
  8. r the database.
  9. --04T11::41.286+ I CONTROL [initandlisten] ** Read and write access to data an
  10. d configuration is unrestricted.
  11. --04T11::41.286+ I CONTROL [initandlisten]
  12. --04T11::41.286+ I CONTROL [initandlisten] Hotfix KB2731284 or later update is not inst
  13. alled, will zero-out data files.
  14. --04T11::41.286+ I CONTROL [initandlisten]
  15. > show dbs
  16. admin .000GB
  17. local .000GB
  18. test .000GB
  19. > use students
  20. switched to db students
  21. > db.class.insert({'name':'吴唐华'})
  22. WriteResult({ "nInserted" : })
  23. > show collections
  24. class
  25. > db.class.drop()
  26. true
  27. > db.class2.insert({'name':'cwl','age':,'sex':})
  28. WriteResult({ "nInserted" : })
  29. > db.class2.insert({'name':'yt','age':,'sex':})
  30. WriteResult({ "nInserted" : })
  31. > db.class2.insert({'name':'jn','age':,'sex':})
  32. WriteResult({ "nInserted" : })
  33. > db.class2.find()
  34. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  35. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  36. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  37. > db.class2.updata({'age':},{$set:{'age':}})
  38. --04T14::23.195+ E QUERY [thread1] TypeError: db.class2.updata is not a function :
  39. @(shell)::
  40. > db.class2.update({'age':},{$set:{'age':}})
  41. WriteResult({ "nMatched" : , "nUpserted" : , "nModified" : })
  42. > db.class2.find()
  43. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  44. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  45. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  46. > db.col.find({"name":{$type:}})
  47. > db.class2.find({"name":{$type:}})
  48. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  49. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  50. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  51. >
  52. > db.class.find()pretty()
  53. --04T15::22.253+ E QUERY [thread1] SyntaxError: missing ; before statement @(shell):
  54. :
  55. > db.class.pretty()
  56. --04T15::30.826+ E QUERY [thread1] TypeError: db.class.pretty is not a function :
  57. @(shell)::
  58. > db.class2.update({'age':{$gt:},{$set:{'sex':}})
  59. ... db.class2.find({"name":{$type:}})
  60. ...
  61. ... db.class2.update({'age':},{$set:{'age':}})
  62.  
  63. > db.class2.update({'age':},{$set:{'age':}})
  64. WriteResult({ "nMatched" : , "nUpserted" : , "nModified" : })
  65. > db.class2.update({'age':},{$set:{'age':}})
  66. WriteResult({ "nMatched" : , "nUpserted" : , "nModified" : })
  67. > db.class2.update({'age':{$gt:}},{$set:{'sex':}},true,true)
  68. WriteResult({ "nMatched" : , "nUpserted" : , "nModified" : })
  69. > db.class2.find()
  70. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  71. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  72. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  73. > db.class2.find().pretty()
  74. {
  75. "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"),
  76. "name" : "cwl",
  77. "age" : ,
  78. "sex" :
  79. }
  80. {
  81. "_id" : ObjectId("5d6f5be99b7e3e911a123a84"),
  82. "name" : "yt",
  83. "age" : ,
  84. "sex" :
  85. }
  86. {
  87. "_id" : ObjectId("5d6f5c139b7e3e911a123a85"),
  88. "name" : "jn",
  89. "age" : ,
  90. "sex" :
  91. }
  92. > db.class2.update({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true)
  93. WriteResult({
  94. "nMatched" : ,
  95. "nUpserted" : ,
  96. "nModified" : ,
  97. "_id" : ObjectId("5d6f69b56685a146689b9147")
  98. })
  99. > db.class2.find()
  100. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  101. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  102. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  103. { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : , "sex" : "yes" }
  104. > db.class2.update({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true)
  105. WriteResult({ "nMatched" : , "nUpserted" : , "nModified" : })
  106. > db.class2.find()
  107. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  108. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  109. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  110. { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : , "sex" : "yes" }
  111. > db.class2.update({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true).find()
  112. --04T15::22.078+ E QUERY [thread1] TypeError: db.class2.update(...).find is not a fun
  113. ction :
  114. @(shell)::
  115. > db.class2.find(db.class2.update({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true))
  116. Error: error: {
  117. "ok" : ,
  118. "errmsg" : "cannot compare to undefined",
  119. "code" : ,
  120. "codeName" : "BadValue"
  121. }
  122. > db.class2.find({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true).find()
  123. --04T15::16.304+ E QUERY [thread1] TypeError: db.class2.find(...).find is not a funct
  124. ion :
  125. @(shell)::
  126. > db.class2.find(db.class2.update({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true))
  127. Error: error: {
  128. "ok" : ,
  129. "errmsg" : "cannot compare to undefined",
  130. "code" : ,
  131. "codeName" : "BadValue"
  132. }
  133. > db.class2.find({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true)
  134. Error: error: {
  135. "ok" : ,
  136. "errmsg" : ">1 field in obj: { age: 12.0, sex: \"yes\" }",
  137. "code" : ,
  138. "codeName" : "BadValue"
  139. }
  140. > db.class2.find({'name':'mgq'},{$set:{'age':,"sex":'yes'}},true,true)
  141. Error: error: {
  142. "ok" : ,
  143. "errmsg" : ">1 field in obj: { age: 12.0, sex: \"yes\" }",
  144. "code" : ,
  145. "codeName" : "BadValue"
  146. }
  147. > db.class2.find()
  148. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : , "sex" : }
  149. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : , "sex" : }
  150. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : , "sex" : }
  151. { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : , "sex" : "yes" }
  152. > db.class2.find({'name':'lys'},{$set:{'age':,"sex":'yes'}},true,true)
  153. Error: error: {
  154. "ok" : ,
  155. "errmsg" : ">1 field in obj: { age: 12.0, sex: \"yes\" }",
  156. "code" : ,
  157. "codeName" : "BadValue"
  158. }
  159. > db.class2.find({'by':'lys'})
  160. > db.class2.find({'by':'lys'})
  161. > db.class2.find({'by':'lys'}).pretty()
  162. > db.class2.insert({'name':'yt','class':'','age':,'money':})
  163. WriteResult({ "nInserted" : })
  164. > db.class2.insert({'name':'clw','class':'','age':,'money':})
  165. WriteResult({ "nInserted" : })
  166. > db.class2.insert({'name':'szy','class':'','age':,'money':})
  167. WriteResult({ "nInserted" : })
  168. > db.class2.insert({'name':'szy','class':'','age':,'money':})
  169. WriteResult({ "nInserted" : })
  170. > db.class.find({$or:[{'class':''},{'class':''}]})
  171. > db.class.find({$or:[{'class':''},{'class':''}]})
  172. > db.class2.find({$or:[{'class':''},{'class':''}]})
  173. { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "class" : "", "age" : , "money"
  174. : }
  175. { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "class" : "", "age" : , "money
  176. " : 20000 }
  177. { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "class" : "", "age" : , "money
  178. " : 20000000 }
  179. { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "class" : "", "age" : , "money
  180. " : 20 }
  181. > db.class2.insert({'name':'lm','class':'','age':,'money':})
  182. WriteResult({ "nInserted" : })
  183. > db.class.find({'money':{$gte:},$or:[{'class':},{'class':''}]}).pretty()
  184. > db.class2.find({'money':{$gte:},$or:[{'class':},{'class':''}]}).pretty()
  185. {
  186. "_id" : ObjectId("5d6f739e9b7e3e911a123a86"),
  187. "name" : "yt",
  188. "class" : "",
  189. "age" : ,
  190. "money" :
  191. }
  192. {
  193. "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"),
  194. "name" : "clw",
  195. "class" : "",
  196. "age" : ,
  197. "money" :
  198. }
  199. > db.class2.find({'money':{$gte:},$or:[{'class':},{'class':''}]},{'_id':,'class':).pre
  200. tty()
  201. ...
  202. ... db.class.find({'money':{$gte:},$or:[{'class':},{'class':''}]},{'class':}).pretty()
  203. ...
  204. ...
  205. >
  206. >
  207. > db.class2.find({'money':{$gte:},$or:[{'class':},{'class':''}]},{'class':}).pretty()
  208. { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "class" : "" }
  209. { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "class" : "" }
  210. > db.class2.find({},{'mame':}).limit()
  211. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83") }
  212. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84") }
  213. > db.class2.find({},{'name':}).limit()
  214. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl" }
  215. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt" }
  216. > db.class2.find({},{'name':,'age':}).sort({'age':-})
  217. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : }
  218. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : }
  219. { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "age" : }
  220. { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "age" : }
  221. { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "age" : }
  222. { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "age" : }
  223. { "_id" : ObjectId("5d6f75509b7e3e911a123a8a"), "name" : "lm", "age" : }
  224. { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : }
  225. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : }
  226. > db.class2.find({},{'name':,'age':}).sort({'age':})
  227. { "_id" : ObjectId("5d6f5ba19b7e3e911a123a83"), "name" : "cwl", "age" : }
  228. { "_id" : ObjectId("5d6f69b56685a146689b9147"), "name" : "lys", "age" : }
  229. { "_id" : ObjectId("5d6f73bb9b7e3e911a123a87"), "name" : "clw", "age" : }
  230. { "_id" : ObjectId("5d6f73f69b7e3e911a123a88"), "name" : "szy", "age" : }
  231. { "_id" : ObjectId("5d6f73ff9b7e3e911a123a89"), "name" : "szy", "age" : }
  232. { "_id" : ObjectId("5d6f75509b7e3e911a123a8a"), "name" : "lm", "age" : }
  233. { "_id" : ObjectId("5d6f5be99b7e3e911a123a84"), "name" : "yt", "age" : }
  234. { "_id" : ObjectId("5d6f5c139b7e3e911a123a85"), "name" : "jn", "age" : }
  235. { "_id" : ObjectId("5d6f739e9b7e3e911a123a86"), "name" : "yt", "age" : }
  236. > db.class2.count()
  237.  
  238. > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}])
  239. { "_id" : "class", "num" : "money" }
  240. > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}])
  241. { "_id" : "class", "num" : "money" }
  242. > db.class2.aggregate([{$group:{_id:'class',num:{$max:'money'}}}])
  243. { "_id" : "class", "num" : "money" }
  244. > db.class2.aggregate([{$group:{'_id':'class',num:{$max:'money'}}}])
  245. { "_id" : "class", "num" : "money" }
  246. > db.class2.aggregate([{$group:{_id:'class',num:{$max:'$money'}}}])
  247. { "_id" : "class", "num" : }
  248.  

mongo数据库基本查询语句的更多相关文章

  1. Oracle数据库,查询语句、内置函数

    一.数据库的查询语句: 1.查询整个表: select * from 表名 例: 2.通过条件查询某一行数据: select * from 表名 where 字段名 例: 3.某一列数据去重查询: s ...

  2. WordPress 常用数据库SQL查询语句大全

    在使用WordPress的过程中,我们少不了要对数据库进行修改操作,比如,更换域名.修改附件目录.批量修改文章内容等等.这个时候,使用SQL查询语句可以大大简化我们的工作量. 关于如何操作SQL查询语 ...

  3. [数据库] SQL查询语句表行列转换及一行数据转换成两列

    原文来自:http://blog.csdn.net/Eastmount/article/details/50559008 本文主要讲述了SQL查询语句表之间的行列转换,同时也包括如何将一行数据转换成两 ...

  4. PHP-- 三种数据库随机查询语句写法

    1. Oracle,随机查询查询语句-20条 select * from (  select  *  from 表名 order by dbms_random.value ) where rownum ...

  5. 小觑数据库(SqlServer)查询语句执行过程

    近年来,越来越多的NoSql产品不断的以技术革命的者的身份跳出来:“你看哥是多么的快,你们关型型数据库真是战五渣阿”.是的,高性能的场景下NoSql真的很出彩.而我们关系型数据库只能在墙角哭泣&quo ...

  6. MYSQL 数据库高频查询语句整理

    一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!>,!<,=>,= ...

  7. 2019-2-14sql server数据库模糊查询语句

    sql server数据库模糊查询语句   确切匹配: select * from hs_user where ID=123 模糊查询 select * from hs_user where ID l ...

  8. MySQL数据库(查询语句)

    用户  角色  权限 select * from students1:查询这个表里的数据 select ssex from students1:在这个表里面查询ssex(性别) select dist ...

  9. 数据库基本查询语句(SQL常用增删改查语句 简单复习 mark)

    SQL常用增删改查语句 1增 1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) ...

随机推荐

  1. Redis设计与实现 -- 动态字符串对象(SDS)

    1. 动态字符串( simple dynamic string, SDS) 在 Redis 中,当需要可以被重复修改的字符串时,会使用 SDS 类型 ,而不是 C 语言中默认的 C 字符串类型 .举个 ...

  2. ORM多对多的实现

    #coding=utf-8 from sqlalchemy import Table, Column, Integer,String,DATE, ForeignKey from sqlalchemy. ...

  3. Linux关闭重启系统

    reboot:重启系统 - 需要root权限 halt:关机 - 需要root权限 poweroff:关机 - 可直接运行

  4. npm run dev 报错:Error: Cannot find module 'webpack-cli/bin/config-yargs'

    使用 npm run dev 时报错: Error: Cannot find module 'webpack-cli/bin/config-yargs' 原因是找不到webpack-cli这个包,使用 ...

  5. java写文件UTF-8格式

    String fileName = dir + File.separator + date + File.separator + (file.list().length + 1) + ".t ...

  6. [POJ1821]Fence(单调队列优化dp)

    [poj1821]Fence 有 N 块木板从左至右排成一行,有 M 个工匠对这些木板进行粉刷,每块木板至多被粉刷一次.第 i 个工匠要么不粉刷,要么粉刷包含木板 Si 的,长度不超过Li 的连续一段 ...

  7. 【串线篇】Mybatis之缓存原理

    所谓二级缓存是名称空间级别的缓存,什么意思呢? TeacherDao.xml首行 <mapper namespace="com.atguigu.dao.TeacherDao" ...

  8. Java反射初识

    反射Class类 Class类是反射的根源,很多很多的类,经过抽象,得出了一个Class类,包括类名,构造方法,属性方法等.得到Class类的对象的三种方式: Object类中的getClass()方 ...

  9. pycharm远程连接的步骤(有一项需特别注意)

    1.设置远程服务器,在这里配置服务器地址等: 要注意下边的这个mappings设置好,跟编译器的path mapping设置为同一个,这里我没设置为同一个,后边就出现了点问题. 2.配置远程的编译器 ...

  10. nyoj 253:LK的旅行 【旋转卡壳入门】

    题目链接 求平面最大点对. 找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板) 关于旋转卡壳算法 #include<bits/stdc++.h> using n ...