I have following code to search in mongo db using spring data mongodb ( version 1.2.3.RELEASE)
Criteria searchCriteria = Criteria.where("NAME").is("TestName")
.and("ID").is("TestID").not().and("Age").is("23");
I got following query ( without not operator )
Query: { "NAME" : "TestName" , "ID" : "TestID", "Age" : "23" }
I was expecting following query
Query: { "NAME" : "TestName" , "$not" : { "ID" : "TestID"}, "Age" : "23" }
What am i doing wrong ?
Any help is greatly appreciated.
Thanks
I used 'ne' instead.
Criteria searchCriteria = Criteria.where("NAME").is("TestName").and("ID").ne("TestID").and("Age").is("23");
Mongo db 'not' is a logical operator.
http://docs.mongodb.org/manual/reference/operator/query/not/
According to the documentation the not() is affecting the clause directly following. That is the .and("Age").is("23"). But you probably have to put it before the is.
Criteria searchCriteria = Criteria.where("NAME").is("TestName").and("ID").not().is("TestID").and("Age").is("23");
If this is not working, try using the andOperator and the not().where("ID") construct.
If you have multiple items then you can use below query for mongo andOperator(Criteria.where(name).nin(ids))
Related
I am now working on loading some data from Snowflake using the REST API called SQL API. The issue is that Snowflake uses some weird format for fields with DATE type when creating the response JSON.
I have this example field metadata:
{
"name" : "...",
"database" : "...",
"schema" : "...",
"table" : "...",
"type" : "date",
"scale" : null,
"precision" : null,
"length" : null,
"collation" : null,
"nullable" : true,
"byteLength" : null
}
And in the resultset its value is "9245". Using the query in the browser I see that the actual value is 1995-04-25.
What magic function decodes this integer back to a date?
Based on documentation Getting the Data From the Results
DATE
Integer value (in a string) of the number of days since the epoch (e.g. 18262).
Related: Why is 1/1/1970 the “epoch time”?
Check:
SELECT DATEADD(day, 9245, '1970-01-01'::DATE)
--1995-04-25
SELECT '1970-01-01'::DATE + INTERVAL '9245 DAYS';
-- 1995-04-25
db<>fiddle demo
I'm trying to pull a specific set of values to insert them into a table in Postgres. I tried using json_populate_recordset, but got nothing.
The basic structure is this:
{
"array_group": [
{"field1" : "value1", "field2" : "value2"},
{"field1" : "value3", "field2" : "value4"}
]
}
Is there another function I should be using or should I try reformatting my JSON structure instead?
I am doing the R&D on the duplicate error scenario in SF Bulk API and found that somehow I am not able to perform insert and update operation simultaneously for the contact with the same(external id) within the single batch.
I received a duplicate error. Screen capture for reference
https://www.screencast.com/t/ReE41vuzb
When the batch contains different external id's I do not have any error. But when external Id is repeated in a single batch I receive the below error.
{
"success" : false,
"created" : false,
"id" : null,
"errors" : [ {
"message" : "Duplicate external id specified: 7401",
"fields" : [ "Origami_ID__c" ],
"statusCode" : "DUPLICATE_VALUE",
"extendedErrorDetails" : null
}
Although there is No duplicate at the target side.
You just need the last record from multiple records with same unique id.
For this follow the below logic:
//Create Map and populate the map with last record having unique id
Map<String,MyObject__c> mapWithUniqueIdMyObject = new Map<String,MyObject__c>();
MyObject__c currentObject;
for(Integer currentPosition = myObjectListWith5000Records.size(); currentPosition >=0 ;currentPosition--){
currentObject = myObjectListWith5000Records.get( currentPosition );
if( !mapWithUniqueIdMyObject.containsKey(currentObject.Origami_ID__c) ){//If the map does not contain any object with unique id then put the object in the map
mapWithUniqueIdMyObject.put( currentObject.Origami_ID__c, currentObject );
}
}
upsert mapWithUniqueIdMyObject.getValues();
I am making a select call on a table and it always returns 1 row. I would like to get the data in json format.
{
"column_name1": "value1",
"column_name2": "value2",
}
Does snowflake query allows anything like this ?
object_construct is the way to go for this.
For example,
select object_construct(*) from t1;
In Kbase database, Is there a syntax can reach to the same effect just like "in" in Mysql?
In kbase database, it uses "+" instead of "in" in Mysql.
For example : where feildName = value1 + value2 + value3......