0
bookHistory:(memberId)=>{

        return new Promise(async(resolve,reject)=>{
           const historyData=await db.get().collection('bookborrow').find({userId:(memberId)}).toArray()
            const bookid=  await historyData.map(element => {
                 return element.data.bookname
             }) 
              console.log(bookid)
              const getBookName=await db.get().collection('bookdetails').find({_id:{$in:[objectid[bookid]]}}).toArray()
              console.log(getBookName)
     })
   } 

historyData is output is look like ['62e53c1ff5d4c45fb7853d9e','62ea6268fd2fe8616cd4c17b'] and i need to data get this _id data from another collection

1

1 Answer 1

1

I suppose you meant to do a search using the ids array. If so, this should work.

import {Types} from 'mongoose';

const historyData=await db.get().collection('bookborrow').find({userId:(memberId)}).toArray()
const bookIds = await historyData.map(element => {
    return new Types.ObjectId(element.data.bookname)
}) 

const getBookName = await db.get().collection('bookdetails').find({
      _id: {
        $in: bookIds
      },
}).toArray()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.