Why can't i get the variable value using $concat - database

As you can see in the following query i'm trying to update the titles of all the movies that got directors as Tom Hanks and i want the title to look like : title->tom hanks
db.movies.updateMany({"directors":"Tom Hanks"},{$set:{"title":{$concat:["$title","->","Tom Hanks"]}}});
But what i got instead is the following :
title: { '$concat': [ '$title', '->', 'Tom Hanks' ] }
what i understood that it doesn't consider it as variable i've looked in many website but i didn't find any answer i hope you can help

Related

MongoDB find in array in all documents

I have a collection of documents with this simplified structure:
{
cards: [
{
id: "some string",
....
},{...}{...}{...}
]
}
I need to query the whole collection of documents and find those documents where my defined ID of a card matches one of the objects in the array of cards.
I usually fetch all documents and do it locally but this is quite large collection and I have no clue how to achieve this if even possible.
Thank you for your time!
ps: I'm using nodejs mongoose
After playing around with mohammad Naimi's solution I figured the correct syntax:
db.collection.find({ cards:{ $elemMatch: { id: { $eq:"some string" }}}})
db.collection.find({cards:{$elemMatch:{id:{$eq:"some string"}}})

Orionjs collection : Expected object, got undefined

I'm experiencing little trouble getting Orionjs working within Angular-Meteor especially with the collections.
I had my old mongodb declarations, for instance :
Gallery = new Mongo.Collection('gallery') and so one.
As the documentation told , I wrote
Gallery = new orion.collection('gallery') but what I get is
Error: Match error: Expected object, got undefined
at exports.check (packages/check/match.js:34:1)
at new orion.collection (packages/orionjs:collections/new.js:8:3)
at meteorInstall.shared.collections.js (shared/collections.js:1:11)
So I tried to start a project from scratch with this framework.
Fact is, it doesn't work neither with Iron Router nor Flow Router.
Can anyone hit me with any hint about it?
Thank you guys.
Ideally OrionJS expect a schema detail like the label for singular and plural names, navigation detail, table layout for displaying data and so on.Here's a typical company collection shown below:
Company = new orion.collection('company', {
singularName: orion.helpers.getTranslation('company.singularName'),
pluralName: orion.helpers.getTranslation('company.pluralName'),
title: orion.helpers.getTranslation('company.title'),
link: {
title: orion.helpers.getTranslation('company.title'),
parent: 'collections-abc'
},
tabular: {
columns: [
{ data: '_id', title: orion.helpers.getTranslation('company.schema.id') },
{ data: 'name', title: orion.helpers.getTranslation('company.schema.name') }
]
}
});
You can also pass a null JSON if you do not wish to show page directly. Usually it expects a JSON like the one shown above.

Referencing arrays that are nested within multiple objects within MongoDB with Express js

So in my MongoDB Collection I have this structure:
"_id" : "Object("-----------")
"name" : "John Doe"
"tool" : {
"hammer" : {
"name" : "hammer 1",
"characteristics" : [
{
"length" : "9 inches"
},
{
"weight" : "4 pounds"
}
]
I know the data may seem a little strange but I can't put the actual data online so I had to input some dummy data. So essentially what I would like to do is be able to update the array that is nested within those objects. So I would like to be able to update the weight or add a new characteristic that I haven't previously entered into it. So for example, add in "metal" : "steel" as a new entry into the array. Currently I'm using a Rest API built in Node.js and Express.js to edit the db. When I was trying to figure out how to dig down this deep I was able to do it with an array at the highest level, however I haven't been able to figure out how to access an array when its embedded like this. So what I was wondering if anybody knew if it was even possible to edit an array this far down? I can post code from controller.js and server.js file if needed but I figured I'd see if it's even possible to do before I start posting it. Any help would be greatly appreciated!
You can use findAndModify to $push it into the array. You have to specify the path precisely though:
db.tools.findAndModify( {
query: { name: "John Doe"},
update: { $push: { tool.hammer.characteristics: {metal: "steel"} }
} );

AngularJS insert data in nested array and sorting with a specific nested array object

I'm a newbie in AngularJS and I want to have a JSON-like nested array in my $scope.tabledata. But everytime I click the add button, nothing happens :( Your ideas will be highly appreciated.
Here's my plunker:
http://plnkr.co/edit/GdoaYI
//Array I want to Achieve
var SampleDataToProduce = {
"Continent":"Asia",
"ContinentId":"ContId1",
"Countries": {
"Japan":
[
{
"Id": 3,
"ColumnIndex": 3,
"ColumnName":"Tokyo",
"Interests":{
"Music":["JRock","JPop"]
}
},
{
"Id": 4,
"ColumnIndex":2,
"DisplayText":"Comment",
"ColumnName": "Osaka",
"Interests":"Music","Anime":{}
}
]
}
}
You have quite a few syntax errors in your scripts. I would suggest you check your syntax thoroughly.
In your addThisColumn function, your tabledata should be $scope.tabledata instead. This is the working function:
$scope.addThisColumn = function () {
$scope.tabledata.push({
Continent : $scope.continent,
ContinentId : $scope.continentid,
Country: $scope.country
})
};
Here is the working plunkr, I am sort of guessing this maybe what you want/need.
At the same time, you may want to read up on the official documentation of AngularJs.
you made some basic mistakes in your code. you didn't used your $scope variables correctly (e.g.: you tried to push into 'tabledata', not '$scope.tabledata').
in your last line tabledata.Countries.Country.push({ColumnIndex: $scope.columnindex}) (where you also should use $scope.tabledata) you are trying to push into Countries.Country, but there is no such field in Countries.
something like $scope.tabledata.Countries[$scope.country] would be possible i guess.
hope that helps, welcome on stackoverflow

Elasticsearch filter on aggregation

Since I couldn't find anything on Google:
Is it possible to filter on an aggregation in elasticsearch. Im thinking of someting like: Get all objects where SUM(obect.X) > 100.
Thanks in advance.
EDIT - Sample Data
I have the following document-structure:
{
docKey : 1
value: 2
},
{
docKey: 1
value: 5
},
{
docKey:1
value: 7
},
{
docKey:2
value:2
},...
I now want to query the docKey from the database where the sum of the value is bigger than X.
EDIT2
I found out that is something I have to do in my application logic.
you can see it here
This doesn't exactly answer your question but seeing as you were pretty vague i.e. posting no mapping, query or anything of that matter we can't help you. However I hope you'll be able to work it out for yourself with this fantastic article on aggregations. Best of luck.
Update - Maybe this is what you're looking for instead?

Resources