output:
{"errors": ["Illegal Argument: invalid type of element"], "info": [ ],
"isSuccessful": false, "warnings": [ ]}
i use the code in .js file is
var procedure1Statement = WL.Server.createSQLStatement("select * from MITS");
function procedure1(param) {
return WL.Server.invokeSQLStatement({
preparedStatement : procedure1Statement,
parameters : [param]
});
}
function procedure2(param) {
return WL.Server.invokeSQLStoredProcedure({
procedure : "storedProcedure2",
parameters : [param]
});
}
may be you can show the code, specially WL.Client.invokeProcedure and the parameters used.
Related
I want to perform a rest request with sencha ext js. Threfore I created a model and a store with a proxy. Then I invoked the load function of the store. The problem is that after the invocation the store is still empty. I know this because I debugged it. This is the code:
var myModel = Ext.create('Ext.data.Model', {
fields: [
{ name: 'name' },
{ name: 'age' }
]
});
var myStore = Ext.create('Ext.data.Store', {
model: myModel,
proxy: {
type: 'rest',
url: 'http://localhost:8080/blablabla',
}
});
myStore.load();
The url 'http://localhost:8080/blablabla' is correct because when I type it in the browser I get the json list of users with the "name" and "age" fields. So the server works.
Here is an example of json that I should get:
[ {
"id" : 1,
"name" : "john",
"age": 40
}, {
"id" : 2,
"name" : "jack",
"age": 30
} ]
My Sencha code was correct. The problem was CORS not enabled. So I resolved by adding #CrossOrigin above my server method.
#CrossOrigin
#RequestMapping
public List<Thing> getThings() {
...
return myListOfThings;
}
#CrossOrigin did the trick.
Hi I am trying to run MongoDB queries inside socket io functions.findOne is working correctly but find and aggregate functions are not working at all.enter code here
mongo.connect('mongodb://localhost:27017', function (err, client) {
const db = client.db('dbName');
const bookWalker = db.collection('bookwalkers');
const walker = db.collection('walkers');
io.sockets.on('connection', function (socket) {
socket.on('enterRoom', function (data) {
socket.room = data.room;
socket.join(data.room);
console.log("connected to room", data.room);
bookWalker.find({"pendingWalk._id":
ObjectId("5bd994d2f395622e0b8f71af")},async function(err,resp) {
console.log("dataf",resp);
io.sockets.in(data.room).emit('getStartTime', resp[0]);
});
});
});
});
this is Sample data in DB
{
"_id" : ObjectId("5bd994d2f395622e0b8f71ad"),
"pendingWalk" : [
{
"walkPicture" : [],
"status" : 0,
"walkPath" : [],
"_id" : ObjectId("5bd994d2f395622e0b8f71af"),
"bookedDate" : ISODate("2018-10-31T13:30:56.581Z"),
"bookedTime" : ""
}
],
"userId" : ObjectId("5b6e932062bce05ae5647980"),
"book_dt" : ISODate("2018-10-31T11:41:06.230Z"),
"__v" : 0}
the query is working fine inside mongo shell.
mongodb find() returns a cursor not array. You have to call toArray() function.
bookWalker.find({"pendingWalk._id":ObjectId("5bd994d2f395622e0b8f71af")}).toArray(function(err,resp){
console.log(resp[0]);
});
I want to write a put method in express for a nested document in mongoose.
I cannot access the id for the nested document.
{ "_id" : ObjectId("5b8d1ecbb745685c31ad8603"),
"name" : "abc",
"email" : "abc#gmail.com",
"projectDetails" : [
{
"technologies" : [
"abc",
"abc"
],
"_id" : ObjectId("5b8d1ecbb745685c31ad8604"),
"projectName" : "abc",
"projectDescription" : "abc",
"manager" : "abc",
"mentor" : "abc"
}
],
"__v" : 0
}
I am trying to access the id ("5b8d1ecbb745685c31ad8604") so that I can update the projectName.
I cannot think of how to write a put method for the same. Please help! Thanks in advance!!
You can use model.findOne() and then save() th update the document instead of model.findOneAndUpdate().
var projectId = "5b8d1ecbb745685c31ad8604";
var newProjectName = "def";
model.findOne({'projectDetails._id': projectId}, (err, data) => {
if (data) {
data.projectDetails.forEach((project) => {
if (project._id == projectId) {
project.projectName = newProjectName;
}
});
data.save();
} else {
// throw error message
}
})
app.put('/api/project/:id',(request,response)=>{
const projectId = request.params.id;
const projectName = "test";
db.users.update({"projectDetails._id":projectId},{$set:{"projectDetails.$.projectName":projectName}},function(err,data){
if(data){
}else{
}
})})
Instead of forEach try above query
I am making a web app. Currently I am storing the messages inside messages columns like below.
I have a column called msges and I have messages as time as key and value details. I want to create a function in which I pass the time, It will return the details of it. Can anyone help me? I can get single field but I don't know how to get it through key value. This is my function.
function getMessageDetails(uname,time,callback){
global.users.find({"uname" : uname,"msges":time},
// {"friends.friendUname":1,_id:0},
{_id:0},
function(err,doc){
if(err){
callback(false,err,"Message not found.",null);
}else{
callback(true,null,"",doc);
}
}
);
}
Thanks in advance. :)
I'd personally try to model your data a bit diffrently, If you had:
{
_id: "123123",
//...
friends: [
{ friendName: "etc..."}
],
msges : [
{
time: "16:25:02",
from: "alizia",
title : "hi buddy",
read: true
},
{
time: "12:25:02",
from: "bob",
title : "hi bobby",
read: false
}
]
}
You'd be able to query the following data by:
db.users.find({_id: "123123", "msges.time" : "16:25:02"}, { "msges.$.from" : 1 })
and will just pull out the one msg based on the query:
{
"_id" : "123123",
"msges" : [
{
"time" : "16:25:02",
"from" : "alizia",
"title" : "hi buddy",
"read" : true
}
]
}
I have the following objects in my Collection that look like the following:
{
"_id" : ObjectId("527d33a8623f6efd1c997440"),
"location" : {
"geometry" : {
"type" : "Point",
"coordinates" : [
-78.4067,
37.26725
]
},
"type" : "Feature",
"properties" : {
"name" : "Something here"
}
},
"name" : "Name of Object"
}
I have the following index:
{
"location.geometry" : "2dsphere"
}
I can do the following:
db.myCollection.find({'location.geometry':{'$near':{'$geometry':{'type':"Point", 'coordinates': [-78.406700,37.267250]}, '$maxDistance' : 1000 }}})
However, I can Not do the following:
db.myCollection.find( { 'location.geometry': { '$geoWithin':
{ '$geometry' :
{ 'type' : "Polygon",
'coordinates' : [ [ -118.108006, 34.046072], [ -117.978230, 34.041521] , [ -117.987328,33.913645 ]] } }
} } )
As it returns with the error:
error: {
"$err" : "can't parse query (2dsphere): { $geoWithin: { $geometry: { type: \"Polygon\", coordinates: [ [ -118.108006, 34.046072 ], [ -117.97823, 34.041521 ], [ -117.987328, 33.913645 ] ] } } }",
"code" : 16535
}
Am I using geoWithin wrong? Can it not be used on this index?
The polygon that you are providing for $geowithin query is incorrect. A polygon needs to have the same start and end point as per GeoJSON definition.
The correct query is:
db.myCollection.find( { 'location.geometry':
{ '$geoWithin':
{ '$geometry' :
{ 'type' : "Polygon",
'coordinates' : [
[ -118.108006, 34.046072],
[ -117.978230, 34.041521],
[ -117.987328,33.913645 ],
[ -118.108006, 34.046072]
]
}
}
}
}
);
Notice the updated coordinates array.
Clearly, what is mentioned here in MongoDB docs about implicit connection of Polygons is NOT incorrect. It says that when you define the polygon using $polygon in MongoDB, only then is the connection implicit. It says nothing about being smart and making an implicit connection in the GeoJSON polygon provided to the query.
In fact, if for some GeoJSON variable you are saying that its type is polygon and you are not connecting its start with the end, then you have not created a correct GeoJSON polygon in the first place.
There is an error in the MongoDB documentation on $geoWithin queries. While the documentation states that:
The last point specified is always implicitly connected to the first.
You can specify as many points, and therefore sides, as you like.
This is incorrect. The polygon needs to be closed. There is an open ticket about this in MongoDB Jira:
https://jira.mongodb.org/browse/DOCS-2029
So your first and last points need to be equal - you cannot depend on MongoDB to implicitly draw the last line of the polygon.