MongoDB下的查询操作(与Java API查询操作对应)

[root@localhost ~]# mongo MongoDB shell version: 1.8.1 connecting to: test gt; db test gt; show collections

相关阅读:

MongoDB Linux下的安装和启动 

MongoDB下的高级查询示例 

MongoDB Java API for 插入和单collection基本查询使用示例

MongoDB下的查询操作(与Java API查询操作对应)

[root@localhost ~]# mongo  
MongoDB shell version: 1.8.1 
connecting to: test  
> db  
test  
> show collections   
data_test  
system.indexes  
system.users  
> db.system.users.find()  
{ “_id” : ObjectId(“4dd73c7d247cb75e4995757b”), “user” : “iwtxokhtd”, “readOnly” : false, “pwd” : “c728e00401a72282a2919648723dbff7” }  
> db.data_test.find()  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”), “userId” : “10010171”, “userName” : “Bill Tu1”, “gender” : “m1”, “interests” : { “game” : “game1”, “ball” : “ball1”, “other” : “nothing1” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a31”), “userId” : “10010172”, “userName” : “Bill Tu2”, “gender” : “m2”, “interests” : { “game” : “game2”, “ball” : “ball2”, “other” : “nothing2” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a32”), “userId” : “10010173”, “userName” : “Bill Tu3”, “gender” : “m3”, “interests” : { “game” : “game3”, “ball” : “ball3”, “other” : “nothing3” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a33”), “userId” : “10010174”, “userName” : “Bill Tu4”, “gender” : “m4”, “interests” : { “game” : “game4”, “ball” : “ball4”, “other” : “nothing4” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a34”), “userId” : “10010175”, “userName” : “Bill Tu5”, “gender” : “m5”, “interests” : { “game” : “game5”, “ball” : “ball5”, “other” : “nothing5” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a35”), “userId” : “10010176”, “userName” : “Bill Tu6”, “gender” : “m6”, “interests” : { “game” : “game6”, “ball” : “ball6”, “other” : “nothing6” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a36”), “userId” : “10010177”, “userName” : “Bill Tu7”, “gender” : “m7”, “interests” : { “game” : “game7”, “ball” : “ball7”, “other” : “nothing7” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a37”), “userId” : “10010178”, “userName” : “Bill Tu8”, “gender” : “m8”, “interests” : { “game” : “game8”, “ball” : “ball8”, “other” : “nothing8” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a38”), “userId” : “10010179”, “userName” : “Bill Tu9”, “gender” : “m9”, “interests” : { “game” : “game9”, “ball” : “ball9”, “other” : “nothing9” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a39”), “userId” : “100101710”, “userName” : “Bill Tu10”, “gender” : “m10”, “interests” : { “game” : “game10”, “ball” : “ball10”, “other” : “nothing10” } }  
> db.data_test.findOne()  
{  
        “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”),  
        “userId” : “10010171”,  
        “userName” : “Bill Tu1”,  
        “gender” : “m1”,  
        “interests” : {  
                “game” : “game1”,  
                “ball” : “ball1”,  
                “other” : “nothing1” 
        }  
}  
> db.data_test.find({“userId”:”10010171″})  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”), “userId” : “10010171”, “userName” : “Bill Tu1”, “gender” : “m1”, “interests” : { “game” : “game1”, “ball” : “ball1”, “other” : “nothing1” } }  
> db.data_test.find({“userId”:”10010171″,”userName”:”Bill Tu1″})  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”), “userId” : “10010171”, “userName” : “Bill Tu1”, “gender” : “m1”, “interests” : { “game” : “game1”, “ball” : “ball1”, “other” : “nothing1” } }  
> db.data_test.find({“userId”:{$in:[“10010171″,”10010172”]}})  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”), “userId” : “10010171”, “userName” : “Bill Tu1”, “gender” : “m1”, “interests” : { “game” : “game1”, “ball” : “ball1”, “other” : “nothing1” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a31”), “userId” : “10010172”, “userName” : “Bill Tu2”, “gender” : “m2”, “interests” : { “game” : “game2”, “ball” : “ball2”, “other” : “nothing2” } }  
> db.data_test.find({“userId”:/10010171.*/i})  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a30”), “userId” : “10010171”, “userName” : “Bill Tu1”, “gender” : “m1”, “interests” : { “game” : “game1”, “ball” : “ball1”, “other” : “nothing1” } }  
{ “_id” : ObjectId(“4dd747cb3a491e68a1a84a39”), “userId” : “100101710”, “userName” : “Bill Tu10”, “gender” : “m10”, “interests” : { “game” : “game10”, “ball” : “ball10”, “other” : “nothing10” } }  
>  

linux

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/1955685.html

(0)
上一篇 2025年2月23日 03:44:13
下一篇 2025年2月23日 03:44:36

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • navicat过期怎么办

    解决 Navicat 过期问题的方法包括:续订许可证;卸载并重新安装;禁用自动更新;使用 Navicat Premium Essentials 免费版;联系 Navicat 客户支持。 Navicat 过期怎么办? Navicat 是一个数…

    2025年2月23日
    100
  • navicat能连接mongodb吗

    是的,Navicat 可以连接到 MongoDB 数据库。具体步骤包括:打开 Navicat 并创建新的连接。选择数据库类型为 MongoDB。输入 MongoDB 主机地址、端口和数据库名称。输入 MongoDB 用户名和密码(如果需要)…

    2025年2月23日
    100
  • navicat类型怎么选

    针对不同需求,Navicat 提供了多种类型:Standard:适用于个人和小型团队,支持基本数据库管理功能。Professional:面向专业人士,新增建模、调试和复制功能。Premium:支持数据迁移和监控,适用于大型企业。Enterp…

    2025年2月23日
    100
  • navicat怎么打开表的连接

    通过 Navicat 访问表连接的步骤: 1. 连接到数据库;2. 浏览至所需数据库;3. 右键单击表,选择“编辑表”;4. 查看表数据。 如何使用 Navicat 打开表的连接 Navicat 是一款功能强大的数据库管理工具,它可以帮助用…

    2025年2月23日
    100
  • navicat怎么连mongodb

    要使用 Navicat 连接 MongoDB,您需要:安装 Navicat创建 MongoDB 连接:a. 输入连接名称、主机地址和端口b. 输入认证信息(如果需要)添加 SSL 证书(如果需要)验证连接保存连接 如何使用 Navicat …

    2025年2月23日
    100
  • Navicat 支持哪些版本的达梦数据库

    Navicat Premium 支持达梦数据库 7 和 8 版本。其他版本,包括 Navicat for MySQL、PostgreSQL、Oracle、SQLite 和 MongoDB,均不支持达梦数据库。 Navicat 支持的达梦数据…

    2025年2月23日
    100
  • Navicat查看MongoDB数据库密码的方法

    直接通过 Navicat 查看 MongoDB 密码是不可能的,因为它以哈希值形式存储。取回丢失密码的方法:1. 重置密码;2. 检查配置文件(可能包含哈希值);3. 检查代码(可能硬编码密码)。 窥探 MongoDB 密码:Navicat…

    2025年2月23日
    100
  • Navicat for MongoDB如何查看数据库密码?

    Navicat for MongoDB 无法查看数据库密码,原因是密码被加密存储,仅持有连接信息。找回密码需要通过MongoDB本身,具体操作取决于部署方式。安全第一,养成良好密码习惯,切勿尝试从第三方工具获取密码,避免安全风险。 Navi…

    2025年2月23日
    100
  • php高级工程师面试问哪些

    PHP高级工程师面试主要考察以下六个方面:基础知识(数据类型、对象编程)、框架和技术栈(Laravel、Composer)、设计模式和最佳实践(单例模式、SOLID原则)、项目经验(大型项目参与)、趋势和新技术(云计算、微服务)、软技能(沟…

    2025年2月23日
    100
  • 在使用php时需要用到哪些软件

    成功使用 PHP 所需软件:文本编辑器或集成开发环境(IDE)Web 服务器PHP 解释器数据库管理系统(DBMS) 使用 PHP 所需软件 PHP (超文本预处理语言) 是一种广泛用于 Web 开发的脚本语言。为了成功使用 PHP,您需要…

    2025年2月23日
    100

发表回复

登录后才能评论