I am using Aqua, a website and user system built using Hapi/React/Flux. http://jedireza.github.io/aqua/
I have a new text field in AccountsForm.jsx called "job". It has correctly added to the db as seen below:
{ _id: ObjectId("569a9fdf9b4fbb060a3f956a"), name: { first: "Dylan", middle: "James", last: "Thomas" }, timeCreated: ISODate("2016-01-16T19:54:07.334Z"), user: { id: "569a9fdf9b4fbb060a3f9569", name: "daylightdylan" }, job: "Web Dev" }
During onDispatcherAction > GET_ACCOUNT_SETTINGS_RESPONSE in account/stores/Account.js I can see that it is setting the this.state values using the values from action.data., which contains "name" and "timeCreated" however my new "job" variable does not exist. Where do I define/add my new variable to action.data so that it is available? I am new to this and I am completely lost!
this.handleResponseErrors(action.data);
this.state.hydrated = true;
this.state.name = action.data.name; ////exists
this.state.job = action.data.job; ////does not exist
this.state.timeCreated = action.data.timeCreated; ////exists
this.emitChange();
Thanks in advance
The fieldsAdapter in the API handler needs to be updated with the new variable that is to be added. For example:
var fields = Account.fieldsAdapter('user name timeCreated');
With new variable added:
var fields = Account.fieldsAdapter('user name job timeCreated');
The fieldsAdapter is a helper method that creates a fields object suitable to use with MongoDB queries.
Related
I have this code, What I am trying to do is create a match and then add the match id to the property "playedMatches" in the player table.
My code creates the match then I add the ID of that created match to the array for "playedMatches" in the player table, everything works fine. However, when I want to push the second played match ID to the array, it deletes all the items in the array and replaces it for the new one created.
In MongoDB I would use the $push Update Operator. Is there something similar I can use for Dynamo DB?
I have also tried with createSet and I get errors every time.
What am I doing wrong?
This is the table structure:
id: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
img:
name: john doe
playedMatches: [xxxxx-xxxxx-xxxx-xxxx-xxxxx]
I want push new id's into playedMatches
const matchId = ['987654321'];
const duplicatedId = '987654321';
const putDataParams = {
TableName: table,
Key: {
id,
},
UpdateExpression: 'set playedMatches = list_append(playedMatches, :matchId)',
ConditionExpression: 'not contains (playedMatches, :duplicatedId)',
ExpressionAttributeValues: {
':matchId': matchId,
':duplicatedId': duplicatedId,
},
ReturnValues: 'UPDATED_NEW',
};
Thanks a lot!
The following function is to return all menu items of a specific type. The types exist in the database but the query is returning no data. Without the query criterion: {type:menuItem}, it returns the data with the the type.
exports.get = async (menuItem) => {
console.log(chalk.green('menuItem', menuItem));
try {
const menu = await Menu.find({type:menuItem});
console.log('menu', menu);
return menu;
} catch(error) {
console.log(error)
}
}
MenuItem logged to the console as shown in the function above produces the following. The problem seem to be with the variable, menuItem, because when I hard-code, {type:'pizza'}, it works.
console.log(chalk.green('menuItem', menuItem));
menuItem 'pizza'
The anuglar query string looks like the following, is there a problem with this:
private menuUrl = '/api/menu?menuItem="pizza"';
Sample data from the database:
{ quantity: 1,
toppings: [ 'chipotle-steak', 'red-onions' ],
_id: 5d163a7ae7179a4e432b501a,
type: 'pizza',
name: 'CHIPOTLE STEAK',
price: 15,
img: 'Chipotle-Steak.png',
}
The key type is used to tell mongoose about the type of that particular field. thats why using type as a field in mongoose schema can sometimes behave ambiguously.
Kindly change type to kind and search with {kind : menuItem} and it should work for you.
Dont forget to update all the docs from type to kind.
To update :
Menu.update({},{$rename : {'type' : 'kind'}},{multi:true})
Then find using kind
const menu = await Menu.find({kind:menuItem});
Silly mistake. The Angular query string had single quotes around pizza:
private menuUrl = "/api/menu?menuItem='pizza'";
It should have been without quotes instead:
private menuUrl = "/api/menu?menuItem=pizza";
I'm just trying to add a number to a number set in DynamoDB. This expression was working with an untyped list. But to save space since it will just be storing numbers I moved everything to plain number sets. Now no matter how much I tinker with it I can't get it to go through.
var phoneID = req.body.PhoneID;
var category = req.body.ratingCategory;
var ratingToAdd = [Number(req.body.rating)]
var dbparams = {
"TableName": "Venue_Ratings",
Key: {
"PhoneID" : phoneID
},
"UpdateExpression": "SET #categoryName = list_append(#categoryName, :rating)",
"ExpressionAttributeNames" : {
"#categoryName" : category
},
"ExpressionAttributeValues": {
":rating": ratingToAdd
},
"ReturnValues": "ALL_NEW"
};
This error is being thrown An operand in the update expression has an incorrect data type
I have also tried changing the update expression to an ADD expression instead like so ADD #categoryName :rating.
I've tried changing ratingToAdd to a plain number not in an array, a string in an array, and a plain string not in an array.
I'm calling the db using the docClient.update method.
I have verified that the sets in the db are in fact number sets and that they exist.
What am I missing here? Thanks for the help.
The below code should add the number to the Number Set (i.e. DynamoDB data type 'NS').
Use this function with ADD in UpdateExpression:-
docClient.createSet([Number(5)])
Code:-
var params = {
TableName : "Movies",
Key : {
"yearkey" : 2016,
"title" : "The Big New Movie 1"
},
UpdateExpression : "ADD #category :categorySet",
ExpressionAttributeNames: {
'#category' : 'category'
},
ExpressionAttributeValues: {':categorySet' : docClient.createSet( [Number(5)])},
ReturnValues: 'UPDATED_NEW'
};
mongoose scheme:
var restsSchema = new Schema({
name: String,
menu: mongoose.Schema.Types.Mixed
});
simplfied document:
{
name: "Dominos Pizza",
menu:{
"1":{
id: 1,
name: "Plain Pizza",
soldCounter: 0
},
"2":{
id: 2,
name: "Pizza with vegetables",
soldCounter: 0
}
}
}
I'm trying to update the soldCounter when given a single/array of "menu items" (such as "1" or "2" objects in the above document) as followed:
function(course, rest){
rest.markModified("menu.1");
db.model('rests').update({_id: rest._id},{$inc: {"menu.1.soldCounter":1}});
}
once this will work i obviously will want to make it more generic, something like: (this syntax is not working but demonstrate my needs)
function(course, rest){
rest.markModified("menu." + course.id);
db.model('rests').update({_id: rest._id},{$inc:{"menu.+"course.id"+.soldCounter":1}});
}
any one can help with this one?
I looked for an answer but couldn't find nothing regarding the 3rd level.
UPDATE:
Added id to the ducument's subDocument
I think you want add all ids into sub-document, one way you can do as following.
Rest.find({_id: rest._id}, function(err, o) {
// add all ids into sub-document...
Object.keys(o.menu).forEach(function(key) {
o.menu[key].id = key;
});
o.save(function(err){ ... });
});
It seems you want to operate the key in query, I am afraid you cannot do it in this way.
Please refer to the following questions.
Mongodb - regex match of keys for subobjects
MongoDB Query Help - query on values of any key in a sub-object
Hi I am facing a problem in updating an embedded object array using mongoose!
Here is the Schema:
var event = {
eTime : [String]
};
var schedule = {
events: [event]
};
var group = {
gName: {type:String},
sDate: { type: Date, default: Date.now },
schedules: [schedule]
};
MainSchema {
id : String,
groups : [group]
};
The thing which I want to do is that to update the array of eTime in events with an object of schedules. I am using this query
db.demoDb.update({
'id': 'MongoDb',
'groups':{
$elemMatch:{
'gName':'noSql'
}
}
},
{
$push:{
'groups':{
'schedules':{
'events':{
'eTime':'01-Marach-15'
}
}
}
}
}
)
but the schedules->events->eventTime is not updating with a value!!!
What wrong I am doing here?
My Main Scenario is to find the id(MongoDB) with associated gName and then update its schedules array of it.
My find query is working great but can not update the schedules... and events can be many
If I'm reading your schema correctly, the core part is an array containing an array containing an array containing an array of strings. I think you would do much better "inverting" the schema so each document represents an event. Metadata grouping multiple events can be duplicated into each event document. An example:
{
"event" : "cookie bake-off",
"gName" : "baking",
"sDate" : ISODate("2015-03-02T21:46:11.842Z")
}
The update that you are struggling with translates into an insertion of a new event document in the collection.