Comments (3)
Hi ya,
So I think that the $elemMatch functionality already exists as ForerunnerDB simply accepts a query against an array field and will scan the sub-documents to ensure they match. If any sub-documents match then the whole parent document is included in the result which kinda makes $elemMatch irrelevant (except for compatibility).
For example if we have a collection with the documents:
[{
_id: '1',
arr: [{
_id: 'jim',
name: 'Jim'
}, {
_id: 'bob',
name: 'Bob'
}]
}, {
_id: '2',
arr: [{
_id: 'alice',
name: 'Alice'
}, {
_id: 'simon',
name: 'Simon'
}]
}]
Then query it with:
{
arr: {
name: 'Jim
}
}
The result will return the document with _id: '1'.
This is what I understand that $elemMatch already does but please correct me if I am wrong! :)
The roadmap item relates to updating documents rather than querying them and it might be that we don't actually need that functionality as there is already a way to identify sub-documents in updates.
from forerunnerdb.
I think to your point update functions are there easiest way to illustrate and most applicable. So I have the following query in Mongoose:
Project.update({"_id":data.id, "categories": {$elemMatch: {_id:data.categoryid}}},{$set: {
"categories.$.name" : data.name,
"categories.$.description" : data.description
}}, function(){
// next...
});
This lets me target a record (which I will call project) with the matching id that also matches the id of a nested array called categories. If those criteria match, it updates the value for name and description for only that specific matched record under the category array, which is again nested in the project.
So to use your structure above, by doing a:
Project.update({"_id": 1, "arr": {$elemMatch: {_id: "bob"}}},{$set: {
"arr.$.name" : "Robert"
}}, function(){
// next...
});
I would get an updated collection of:
[{
_id: '1',
arr: [{
_id: 'jim',
name: 'Jim'
}, {
_id: 'bob',
name: 'Robert'
}]
}, {
_id: '2',
arr: [{
_id: 'alice',
name: 'Alice'
}, {
_id: 'simon',
name: 'Simon'
}]
}]
Again, I think this works closely with the $set operator which is part of the update process. Can you give me an example of identifying sub documents in updates? Specifically using arrays as sub documents? Maybe I missed something in the documentation. :)
from forerunnerdb.
$elemMatch (projection) has been added to ForerunnerDB for find() calls. Calls to update() still need to have that functionality added specifically with $elemMatch operators, however a I mentioned above you can specify a sub-array document to be updated already.
from forerunnerdb.
Related Issues (20)
- Clarity about find(); HOT 2
- upsert that resolves to update does not update fields that start with '$' HOT 5
- TypeError: http.IncomingMessage.prototype is not an object or null HOT 6
- Support for $not operator HOT 3
- Interactive Demo HOT 1
- index not used when using query operator
- collection.load is very slow HOT 1
- Loading JSON file into forrunner db file and vice versa ? HOT 8
- Duplicate data when setData and ensureIndex HOT 1
- Adding event listener with an ID does not work HOT 2
- Dropping condition does not remove memory reference
- $replace with new documents?
- How does load work? HOT 2
- using Date query with $gte and $lte operators. HOT 3
- Typescript is outdated HOT 3
- Where can i find the database file?
- Weird query behavior when using elemMatch
- WebWorker import ForerunnerDB
- ⚠️ Web SQL is deprecated
- How to query condition on comparing 2 fields?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forerunnerdb.