Mi esquema de Mangosta:
var book_listSchema = new mongoose.Schema({ userId: { type: String, required: true }, first_name: { type: String, required: true }, last_name: { type: String, required: true }, newList: [], });En Express tengo la función de post
router.post('/fileExpress/:title&:author?',... var list_name = req.body.list; var title = req.params.title; var author = req.params.author; addToList[list_name] = [{book_name: title, book_author:author, date_added: new Date()}];Agregué esta matriz a newList a través del comando push de mongoose.
book_list.findOneAndUpdate({"userId": req.userContext.userinfo.sub},{ $push:{newList: addToList}},Esto envía datos a MongoDB que se ven así:
newList:Array 0:Object read:Array 0:Object book_name:"A Game of Thrones" book_author:"George RR Martin" date_added:2022-04-14T21:23:59.815+00:00Dentro de esta función de publicación tengo el comando Mongoose
book_list.findOne({"userId":req.userContext.userinfo.sub,"newList.list_name.book_name":title
La sección de código newList.list_name.book_name no funciona con la variable list_name . Funciona cuando escribo el nombre de la lista real. En este caso, 'list_name' es 'leer'.
Estoy usando esto porque habrá listas con muchos nombres diferentes y una función debe funcionar para todos ellos.