插入后找不到 returns 任何内容

Find returns nothing after an insert

我正在尝试了解如何使用 mongo 并获得特定的结果集。我觉得有点傻,因为我在互联网上找不到关于它究竟如何工作的资料,这对大多数人来说一定是非常明显的。

如果可以谷歌搜索,请帮助我找到合适的关键字,因为我没有通过那条路线到达我需要去的地方:)

 Meteor.startup(function() {
    Users.remove({}); //reset test

    if (Users.find().count() === 0) {
        Users.insert([
            {username : 'Daan'   , password : "test2"},
            {username : 'Miranda', password : "test1"}
        ]);
        console.log(Users.find({}).fetch());
        console.log(Users.find({username : 'Daan'}).fetch());
    }
});

使用 {username : 'Daan'} 进行的查找没有找到任何结果。 使用 ({}) returns 查找数组中的两条记录

Collection.insert 只接受一个文档。试试这个:

Users.insert({username: 'Daan', password: "test2"});
Users.insert({username: 'Miranda', password: "test1"});

请注意,您可能希望使用 accounts-password 而不是生成您自己的 Users 集合。