简体   繁体   中英

How can i search for a value inside an object with using findOne in Mongodb

在此处输入图像描述

this is my MongoDB data

an I have to get the token->token data

const doc = JSON.parse(reqTest);
  const database = client.db("loginapi");
  const movies = database.collection("users");

const finder=await movies.findOne({token:{token:doc.token}});

I tried to use this but it didn't work.

Since token is an Object in your document, you have to use 'token.token' to match the strings.

movies.findOne({ 'token.token': doc.token })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM