我正在尝试使用node.js从服务器数据库中获取数据
代码:
const start = async () => {
let oldDB = mongoose.createConnection('mongodb://url:27017/datatool' , { useMongoClient: true, user: 'datahub', pass: 'HappyPetter321' });
const clients = await oldDB.model('clientaccount', OldClientSchema).find({});
console.log(JSON.stringify(clients,undefined,2));
console.log(`obtained ${clients.length} records from database.`);}
start();
实际上,我得到了一些这样的数据:
[
{
"_id": "5b938e2ef2cd6880f44d120c",
....,
....,
},
{...},
{...}
]
但是奇怪的是,当我在也连接到同一数据库的Robo 3T中尝试db.getCollection('clientaccount').find({{"_id" : ObjectId("5b938e2ef2cd6880f44d120c")}})
时,结果是Fetched 0 record(s) in 15ms
。
有人对此有想法吗?