Mongodb - regex match of keys for subobjects -


I have some documents saved in the archive (such as urls ) which look like this:

  {payload: {url_google.com: {url: 'google.com', text: 'search'}}}, {payload: {url_t.co: {url: 't. Co ', text:' url shortener '}}}, {payload: {url_facebook.com: {url:' facebook.com ', text:' social network '}}}   

Mongo CLI, is it possible to see sub-topics of payload ? That match / ^ url _ / ? And, if it is possible, then will it be possible to question the match subobabic (for example, make sure that text exists)?

I was thinking something like this:

  db.urls.find ({"payload": {"$ regex": / ^ url _ /}} ). Count ();   

But this 0 result is returning.

Any help or suggestion would be great.

Thank you,

Matt

document like this It is not possible to ask about the keys. You can search for exact matches using $ exists , but you can not find names that match a pattern.

I think (maybe wrongly) you are trying to find documents is a URL sub-document, and that it will not be in all the documents? Why not, push that type of information under one level, something like this:

  {payload: {type: "url", url: "Facebook.com", ...}}   

Then you can query this way:

  db.foo.find ({"payload.type": "url", .. }}   

If I did not know that I should not use dots (. ), it is possible to create such documents in some cases, But this will be a cause of great confusion because you have embedded documents (where the dot dot "Path tries to ask questions dot is) to speak as separator".

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -