A
A
Anastasia2021-05-09 23:55:07
MongoDB
Anastasia, 2021-05-09 23:55:07

How to get multiple records in MongoDB with different ones?

Hello. I am familiar with Cockpit CMS and it uses MongoDB. I need to get the records where the field name = z,x and c.

Here is a query that displays a record with name = z without any problems.

fetch('/cms/api/collections/get/ende?token=account-2d62f0209212457d0138c79cefaa06', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        filter: {name: 'z'},
    })
})
.then(res=>res.json())
.then(res => console.log(res));

But this condition does not work:
filter: {$and: [{name: 'x'},{name: 'z'},{name:"с"}] }

does not display any records at all. I've already tried hundreds of layout options... What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirillinyakin, 2021-05-09
@nastya97core

Hmm, I'm not familiar with MongoDB yet, but maybe instead of $and you should write $or

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question