Querry an Array as beeing part of my User Scheme in my User collection

const data = {
users: [{
name: ‘Chippu’,
email: ‘florianweise@gmx.de’,
hashedPassword: bcryptjs.hashSync(‘123456’),
wallet: [{blockchain: “Solana”, wallet: ‘8jyvEbTeUtKJAvQMeNsCR2hsguwWAm8Kp4oFK7n5XkAp’}, {blockchain: “Etherum”, wallet: ‘0x4aB10fbE398287672b8c48d1f59C741FA9B895eF’}],
avatar: “…”
discord: ‘#Chippu652728’,
instagram: ‘Woauchimmer’,
projects: [
name: ‘miniroyale’,
path: ‘miniroyale’,
logo: ‘…’,
banner: ‘h…’,
‘Mini Royale: Nations is a browser-based first-person-shooter set on top of a land strategy game. Players can earn mintable items through Battle Pass and Quests, join or create Clans to participate in Clan Wars, fuse weapons and characters for ultra rare skins, and more.’,
blockchain: ‘Solana’,
policyID: ‘DkihrQwDWTUsCzPAGZa8TUEc3UcKSY2KKHV98cBNiXjX’,
tokenAdresse: ‘FcvPATycd7uEKZJ5rAsv9fNyu51j4EhzgmoE6FCAgxBW’,
website: ‘https://miniroyale.io/’,
twitter: ‘@MiniNations’,
discord: ‘hmmm’,
instagram: ‘Woauchimmer’,
admins: [{key: “”, name: “Chippu”}],

Hi this is my data for now. I try the following code from my backend node js:

const user = await User.findOne({wallet: {wallet: addresse}}).clone();

But the results are null. I have no idea, how to query the array behind the property wallet. Any hint would be super awesome. Thank you in advance.

Hello @Florian_Weise ,

Welcome to The MongoDB Community Forums! :wave:

To query the array behind the wallet property, you can use the dot notation in your query to specify the nested field. Here’s an example:

const user = await User.findOne({'wallet.wallet': address}).clone();

This will find a document where the wallet field is an array containing an object with a wallet property equal to address.

To learn more, please refer Query an Array of Embedded Documents.

Note: If there are multiple objects in the wallet array that match the query, only the first one will be returned. If you want to find all matching documents, you can use the find method instead of findOne.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.