Neo4j cypher query on ID returns no values via REST but does via Data Browser - rest

Neo4j version 1.8.M06
The following query executed in the Data Browser on the web management interface returns a value for the Forename property:
start n=node(*) where ID(n)=147 return n.Forename
However the same query posted using the REST API
{
"query" :
"start n=node(*) where ID(n)={id} return n.Forename",
"params" :
{"id" : "147"}
}
Returns:
{
"columns" : [ "n.Forename" ],
"data" : [ ]
}
Any idea what I'm doing wrong?

You don't want quotes around 147 in the REST call.
Also, maybe it's because of your simplification, but I'm pretty sure you should really be doing start n=node({id}) instead, for optimum performance. Not sure if it optimizes that sort of thing out.

Related

Any default APIs in Dolibarr for creating sales order records?

Dolibarr has a module for restful APIs.
The API explorer seems to show all the CRUD tasks for each module like orders, stock and customer.
But to CREATE a record, the sample VALUE for the POST method shows as:
{
"request_data": [
"string"
]
}
What are the specific field attributes that should go in here?
Where can I look up the field requirements?
You should take a look at the attributes of the Commande class:
https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/commande/class/commande.class.php
The object should be something like this :
{
"date_commande" : "0000-00-00 00:00:00",
"date_livraison" : "0000-00-00 00:00:00",
"attribute3": "and so on"
}
When you need a parameter like
{ "request_data": [ "string" ] } for a POST API, all you have to do is to call the similar API to get a record (so the same API with the GET method). The result can be cut and paste to be used to create a new record (just change the id and ref in the answer retreived by the GET).

Storing a query in Mongo

This is the case: A webshop in which I want to configure which items should be listed in the sjop based on a set of parameters.
I want this to be configurable, because that allows me to experiment with different parameters also change their values easily.
I have a Product collection that I want to query based on multiple parameters.
A couple of these are found here:
within product:
"delivery" : {
"maximum_delivery_days" : 30,
"average_delivery_days" : 10,
"source" : 1,
"filling_rate" : 85,
"stock" : 0
}
but also other parameters exist.
An example of such query to decide whether or not to include a product could be:
"$or" : [
{
"delivery.stock" : 1
},
{
"$or" : [
{
"$and" : [
{
"delivery.maximum_delivery_days" : {
"$lt" : 60
}
},
{
"delivery.filling_rate" : {
"$gt" : 90
}
}
]
},
{
"$and" : [
{
"delivery.maximum_delivery_days" : {
"$lt" : 40
}
},
{
"delivery.filling_rate" : {
"$gt" : 80
}
}
]
},
{
"$and" : [
{
"delivery.delivery_days" : {
"$lt" : 25
}
},
{
"delivery.filling_rate" : {
"$gt" : 70
}
}
]
}
]
}
]
Now to make this configurable, I need to be able to handle boolean logic, parameters and values.
So, I got the idea, since such query itself is JSON, to store it in Mongo and have my Java app retrieve it.
Next thing is using it in the filter (e.g. find, or whatever) and work on the corresponding selection of products.
The advantage of this approach is that I can actually analyse the data and the effectiveness of the query outside of my program.
I would store it by name in the database. E.g.
{
"name": "query1",
"query": { the thing printed above starting with "$or"... }
}
using:
db.queries.insert({
"name" : "query1",
"query": { the thing printed above starting with "$or"... }
})
Which results in:
2016-03-27T14:43:37.265+0200 E QUERY Error: field names cannot start with $ [$or]
at Error (<anonymous>)
at DBCollection._validateForStorage (src/mongo/shell/collection.js:161:19)
at DBCollection._validateForStorage (src/mongo/shell/collection.js:165:18)
at insert (src/mongo/shell/bulk_api.js:646:20)
at DBCollection.insert (src/mongo/shell/collection.js:243:18)
at (shell):1:12 at src/mongo/shell/collection.js:161
But I CAN STORE it using Robomongo, but not always. Obviously I am doing something wrong. But I have NO IDEA what it is.
If it fails, and I create a brand new collection and try again, it succeeds. Weird stuff that goes beyond what I can comprehend.
But when I try updating values in the "query", changes are not going through. Never. Not even sometimes.
I can however create a new object and discard the previous one. So, the workaround is there.
db.queries.update(
{"name": "query1"},
{"$set": {
... update goes here ...
}
}
)
doing this results in:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 52,
"errmsg" : "The dollar ($) prefixed field '$or' in 'action.$or' is not valid for storage."
}
})
seems pretty close to the other message above.
Needles to say, I am pretty clueless about what is going on here, so I hope some of the wizzards here are able to shed some light on the matter
I think the error message contains the important info you need to consider:
QUERY Error: field names cannot start with $
Since you are trying to store a query (or part of one) in a document, you'll end up with attribute names that contain mongo operator keywords (such as $or, $ne, $gt). The mongo documentation actually references this exact scenario - emphasis added
Field names cannot contain dots (i.e. .) or null characters, and they must not start with a dollar sign (i.e. $)...
I wouldn't trust 3rd party applications such as Robomongo in these instances. I suggest debugging/testing this issue directly in the mongo shell.
My suggestion would be to store an escaped version of the query in your document as to not interfere with reserved operator keywords. You can use the available JSON.stringify(my_obj); to encode your partial query into a string and then parse/decode it when you choose to retrieve it later on: JSON.parse(escaped_query_string_from_db)
Your approach of storing the query as a JSON object in MongoDB is not viable.
You could potentially store your query logic and fields in MongoDB, but you have to have an external app build the query with the proper MongoDB syntax.
MongoDB queries contain operators, and some of those have special characters in them.
There are rules for mongoDB filed names. These rules do not allow for special characters.
Look here: https://docs.mongodb.org/manual/reference/limits/#Restrictions-on-Field-Names
The probable reason you can sometimes successfully create the doc using Robomongo is because Robomongo is transforming your query into a string and properly escaping the special characters as it sends it to MongoDB.
This also explains why your attempt to update them never works. You tried to create a document, but instead created something that is a string object, so your update conditions are probably not retrieving any docs.
I see two problems with your approach.
In following query
db.queries.insert({
"name" : "query1",
"query": { the thing printed above starting with "$or"... }
})
a valid JSON expects key, value pair. here in "query" you are storing an object without a key. You have two options. either store query as text or create another key inside curly braces.
Second problem is, you are storing query values without wrapping in quotes. All string values must be wrapped in quotes.
so your final document should appear as
db.queries.insert({
"name" : "query1",
"query": 'the thing printed above starting with "$or"... '
})
Now try, it should work.
Obviously my attempt to store a query in mongo the way I did was foolish as became clear from the answers from both #bigdatakid and #lix. So what I finally did was this: I altered the naming of the fields to comply to the mongo requirements.
E.g. instead of $or I used _$or etc. and instead of using a . inside the name I used a #. Both of which I am replacing in my Java code.
This way I can still easily try and test the queries outside of my program. In my Java program I just change the names and use the query. Using just 2 lines of code. It simply works now. Thanks guys for the suggestions you made.
String documentAsString = query.toJson().replaceAll("_\\$", "\\$").replaceAll("#", ".");
Object q = JSON.parse(documentAsString);

Error: adding rows with smartsheet API

I can't seem to get a add row(s) to work. I get the following error, but I believe the data is formatted correctly. Thanks in advance!
{"errorCode":1008,"message":"Unable to parse request. The following error occurred: Request body must be either a JSON object or JSON array."}
POST https://api.smartsheet.com/1.1/sheet/{sheetId}/rows
ContentType=application/json
[
{
"toBottom" : true,
"cells" : [
{"columnId" : "328984295696260", "value" : 888.0},
{"columnId" : 4832583923066756, "value" : 100.0}
]
},
{
"toBottom" : true,
"cells": [
{"columnId" : "328984295696260", "value" : 999.0},
{"columnId" : 4832583923066756, "value" : 100.0}
]
}
]
Looks like you've encountered a bug with the API 1.1 "Add Row(s)" endpoint. I get the same error as you report when attempting a similar request using the API 1.1 endpoint -- but it works fine with the API 2.0 endpoint.
I'd suggest that you try using the API 2.0 "Add Row(s)" endpoint instead:
POST https://api.smartsheet.com/2.0/sheets/{sheetId}/rows
API 1.1 has been deprecated (see announcement here), so you should be using API 2.0 for any new API development. The API 2.0 documentation can be found here.
PS - for good measure (although it's not the cause of your issue) -- I'd suggest that you remove quotation marks from around the first numerical columnId value in each cells collection, as they're not necessary.

Why does my Collection.find().count() always returns 0 at client?

I have a Collection containing 1.7 million documents. When executing count() on server side console I get correct results.
meteor:PRIMARY> db.postcodes.find().count();
1737697
meteor:PRIMARY>
Whereas at the browser console I always get zero for count() and for findOne() returns undefined.
insecure package has not been removed. And count() and findOne() are working for other smaller Collections.Not much code is present at the moment. Apart from the default html, js, css. Only a couple of line of code is present. I have model.js living in its own folder (neither in Server nor in Client) that has
PostCodes = new Mongo.Collection('postcodes');
Hello = new Mongo.Collection('hello');
All the Collections I have at the moment is
meteor:PRIMARY> db.getCollectionNames();
[
"hello",
"meteor_accounts_loginServiceConfiguration",
"parttimejobs",
"postcodes",
"system.indexes",
"users"
]
meteor:PRIMARY>
Package I have are
autopublish 1.0.3
ian:accounts-ui-bootstrap-3 1.2.69
insecure 1.0.3
meteor-platform 1.2.2
twbs:bootstrap 3.3.5
Sample document
meteor:PRIMARY> db.postcodes.findOne();
{
"_id" : ObjectId("559933dc4a8617644069fa5b"),
"postcode" : "AB10 1AB",
"latitude" : 57.149079,
"longitude" : -2.096964,
"county" : "",
"district" : "Aberdeen City",
"ward" : "George St/Harbour",
"constituency" : "Aberdeen North",
"loc" : [
-2.096964,
57.149079
]
}
Assuming you are trying to do count() very early on when the app launches, it does not seem like the data is ready (due to the large amount that needs to be loaded).
If you just need the count, I would recommend using a Meteor Method and asynchronously get the count, so you don't have to wait for the the client subscription to be ready for 1.7 million documents.
Below is an example of a method:
On the server:
Meteor.methods({
getSomeCollectionCount: function () {
return someCollection.find().count();
}
});
Then on the client:
Meteor.call('getSomeCollectionCount', function (error, result) {
if(!error) {
// add code to be run when count is ready
console.log('someCollection count: ', result);
}
});
The other way is to use pub-sub or iron router waiton, but if you are just trying to get the count I would not recommend the client subscribing to all 1.7 million documents.
As many mentioned, this was due to large volume of data. Expected results are returned after removing autopublish and creating a channel.
Meteor.publish('postCodesChannel', function(){
return PostCodes.find({postcode: {$regex: /B14 6B[DE]/}});
});
Browser console now returns appropriate values
>PostCodes.find().count();
2

MongoHub remove data

Looked everywhere online and can't find a simple answer to how to delete an id from MongoDB using MongoHUB.
In MongoHub I click on remove and i get presented with this above the query box:
db.site.markets.remove()
i want to remove this data:
{
"_id": 10,
"item": "box",
"qty": 20
}
Surely this code should work?
db.site.markets.remove(item : 'box' )
or
db.site.markets.remove(_id : 10)
Both of them don't work.
I'm making this too difficult... Stupid though it may sound a right click, delete function would be helpful...
When removing using mongohub you must wrap the parameters in quotes.
{"item" : "box"}
Also when removing by mongodb built in id the ObjectId() function is also required.
{ "_id" : ObjectId( "12345")}
You should give an object to mongodb. And _id column generated by mongodb is type of ObjectId, so you should use ObjectId("10") when passing the parameter as below:
db.site.markets.remove({item : 'box'})
db.site.markets.remove({_id : ObjectId('10')})