mongodb:3.6.5
node:9.9.0
koa:2.5.0
npm-mongodb:3.0.5
problems encountered:
query with findOne/find with projection parameters
return results in node with deleted fields
router.post("/manage", async(ctx, next) => {
var users = db.collection("user");
var doc = await users.findOne({userName:"yunf"},{_id:0});
var doc1 = await users.find({userName:"yunf"},{_id:0}).toArray();
console.log(doc);
console.log(doc1 );
});
//
// {
// _id: 5ac1cfe24a814acb143e3084,
// userName: "yunf",
// authority: "00000000010000",
// cerationTime: "",
// updateTime: 2018-04-06T06:18:55.188Z,
// userPwd: "$2a$10$IA7/C9fplPoxY6ilTbadyeBJjAxHRUIgP.ezOQqYMCv7vHXPhx39u"
// }...
but the same code shell returns
the find () query for documents that have looked up mongodb 3.6returns the fields returned by cursors that can be specified with project
var cursor3 = db.collection("user").find({}).project({_id: 0 }).toArray();
// { userName: "yunf"}]
but why does querying with findOne/find with projection parameters not work
is a version problem? Ask the boss for advice!