我有一个node.js应用程序,它提取一些数据并将其粘贴到一个对象中,就像这样:

var results = new Object();

User.findOne(query, function(err, u) {
    results.userId = u._id;
}

当我基于存储的ID执行if/then时,比较永远不会为真:

if (results.userId == AnotherMongoDocument._id) {
    console.log('This is never true');
}

当我对这两个id执行console.log时,它们完全匹配:

User id: 4fc67871349bb7bf6a000002 AnotherMongoDocument id: 4fc67871349bb7bf6a000002

我假设这是某种数据类型问题,但我不确定如何转换结果。userId转换为一个数据类型,这将导致上述比较是正确的,我的外包大脑(又名谷歌)一直无法提供帮助。

如何在Wireshark上捕获移动电话流量?

我如何(在MongoDB)结合数据从多个集合到一个集合?

我可以使用地图减少,如果是,然后如何?

我非常感谢一些例子,因为我是一个新手。

使用Flask,我如何读取HTTP头?我想检查客户端发送的授权头。

我正在尝试添加授权到我的MongoDB。 我使用MongoDB 2.6.1在Linux上完成所有这些工作。 我的mongo .conf文件是旧的兼容格式 (这就是安装的方式)。

1)我创建了admin用户,如(3)所述

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2)然后我通过取消注释这一行来编辑mongo .conf

真实的

3)最后,我重启了mongod服务,并尝试登录:

/usr/bin/mongo localhost:27017/admin -u sa -p PWD

4)我可以连接,但它说这个连接。

MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }

5)现在我创建的sa用户似乎没有任何权限。

root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
[admin] 2014-05-29 17:57:03.011 >>> use admin
switched to db admin
[admin] 2014-05-29 17:57:07.889 >>> show collections
2014-05-29T17:57:10.377-0400 error: {
        "$err" : "not authorized for query on admin.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[admin] 2014-05-29 17:57:10.378 >>> use test
switched to db test
[test] 2014-05-29 17:57:13.466 >>> show collections
2014-05-29T17:57:15.930-0400 error: {
        "$err" : "not authorized for query on test.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[test] 2014-05-29 17:57:15.931 >>>

有什么问题吗?我把整个过程重复了三次 我想我做的都是在MongoDB文档中指定的。但这并不奏效。 我期望这个sa用户被授权做任何事情,以便 然后,他可以创建其他用户,并给予他们更具体的权限。

db.foo.find().limit(300)

不会这么做的。它仍然只打印了20份文件。

db.foo.find().toArray()
db.foo.find().forEach(printjson)

将打印每个文档的扩展视图,而不是find()的一行版本:

我正在用Node.js和mongoose写一个web应用程序。如何对我从.find()调用得到的结果进行分页?我想要一个功能可比的“限制50,100”在SQL。

我知道如何列出一个特定的数据库中的所有集合,但我如何列出MongoDB shell中所有可用的数据库?

我有一个叫做people的mongodb集合 其架构如下:

people: {
         name: String, 
         friends: [{firstName: String, lastName: String}]
        }

现在,我有一个非常基本的快速应用程序连接到数据库,并成功地创建“人”与一个空的朋友数组。

在应用程序的次要位置,有一个添加好友的表单。表单接收firstName和lastName,然后是带有名称字段的POSTs,同样用于引用适当的people对象。

我有一个困难的时间做的是创建一个新的朋友对象,然后“推”到朋友数组。

我知道当我通过mongo控制台这样做时,我使用$push作为查找标准后的第二个参数的更新函数,但我似乎找不到合适的方法让猫鼬这样做。

db.people.update({name: "John"}, {$push: {friends: {firstName: "Harry", lastName: "Potter"}}});

假设mongodb文档(表)“用户”是

{
    _id: 1,
    name: {
        first: 'John',
        last: 'Backus'
    },
    birth: new Date('Dec 03, 1924'),
    death: new Date('Mar 17, 2007'),
    contribs: ['Fortran', 'ALGOL', 'Backus-Naur Form', 'FP'],
    awards: [
        {
            award: 'National Medal',
            year: 1975,
            by: 'NSF'
        },
        {
            award: 'Turing Award',
            year: 1977,
            by: 'ACM'
        }
    ]
}
// ...and other object(person)s

我想找到那个必须在1975年被授予“国家勋章”的人 可能还有其他人在不同的年份获得过这个奖项。

我如何使用奖项类型和年份找到这个人。这样我就能得到准确的人。