node.jsmongodbvector-search

How to delete data from Vector Search in Mongodb


I have created a vector search index on my collection in MongoDB, Now I want to delete some data from it let's say data is added with bookId=1, I tried deleting the data with

db.collection('inventory').deleteMany({"bookId":"1"});

But it's not deleted, Also Find() is also not returning the data.


Solution

  • you need to use async await for the same. Either use the statement in an async function

    async function deleteData() {
         const res = await db.collection('inventory').deleteMany({"bookId":"1"});
         console.log(result)
    }
    

    or you can use callback.

    db.collection('inventory').deleteMany({"bookId":"1"}).then((result) => {
         console.log(result);
    })