Monday 27 April 2020

How can I set both ObjectId and UserId in MongoDB(Image attached)

I saw an example online where there is an ObjectId and also the productId as seen in the image below.https://preview.redd.it/xjlocwqc5ev41.png?width=1260&format=png&auto=webp&s=ebfc4ea40eb1628d7a548fde5a6d876cf53c8ce8I have a schema that looks like thisimport * as mongoose from 'mongoose'; import * as bcrypt from 'bcrypt';export const UserSchema = new mongoose.Schema({ userId: { type: mongoose.SchemaTypes.ObjectId,     }, firstname: { type: String, required: true     }, lastname: { type: String, required: true     }, });With this schema, I can only see the objectId the DB, and every time I do thislet user = await this.userModel.findById({ '_id': new ObjectId(id) }) I get this errorCannot find name 'ObjectId'. Did you mean 'Object'?ts(2552) lib.es5.d.ts(267, 13): 'Object' is declared here. So I think it will be ok to get BOTH userId and document ObjectId just like what is in the image above\Thanks

Submitted April 27, 2020 at 06:10PM by techstackng

No comments:

Post a Comment