find-and-modify "No value supplied for key: {:return-new true}"

74 views
Skip to first unread message

Ahmad Hammad

unread,
Oct 13, 2014, 7:16:07 AM10/13/14
to clojure...@googlegroups.com
Hi,

I this function works without the :return-new map, however with it I get ""No value supplied for key: {:return-new true}":

(defn get-next-sequence [project-key]
  (mc/find-and-modify "projects" 
                      {:key project-key}
                      {$inc {:seq 1}}
                      {:return-new true}))

java.lang.IllegalArgumentException: No value supplied for key: {:return-new true} PersistentHashMap.java:77 clojure.lang.PersistentHashMap.create collection.clj:230 monger.collection/find-and-modify RestFn.java:467 clojure.lang.RestFn.invoke

based on this (https://github.com/michaelklishin/monger/blob/ef539f48c8c6a880c7c4e0ced2eff7d4631a0cb6/test/monger/test/atomic_modifiers_test.clj#L413) the syntax looks correct.

Another question, the $inc is updating the attribute with a java "NumberLong(1)", why doesn't it just use the number itself? And how do I opt out of using the java type in the db?

Thanks

Michael Klishin

unread,
Oct 13, 2014, 12:01:09 PM10/13/14
to clojure...@googlegroups.com, Ahmad Hammad


On 13 October 2014 at 19:55:37, Ahmad Hammad (ah...@buttercloud.com) wrote:
> > I this function works without the :return-new map, however
> with it I get ""No value supplied for key: {:return-new true}":
>
> (defn get-next-sequence [project-key]
> (mc/find-and-modify "projects"
> {:key project-key}
> {$inc {:seq 1}}
> {:return-new true}))
>
>
>
> java.lang.IllegalArgumentException: No value supplied for
> key: {:return-new true} PersistentHashMap.java:77 clojure.lang.PersistentHashMap.create
> collection.clj:230 monger.collection/find-and-modify
> RestFn.java:467 clojure.lang.RestFn.invoke
>
> based on this (https://github.com/michaelklishin/monger/blob/ef539f48c8c6a880c7c4e0ced2eff7d4631a0cb6/test/monger/test/atomic_modifiers_test.clj#L413)
> the syntax looks correct.

All monger.collection functions require a connection object to be passed to them as of 2.0:

https://github.com/michaelklishin/monger/blob/master/ChangeLog.md#changes-between-180-and-200

you are not passing it.

> Another question, the $inc is updating the attribute with a java
> "NumberLong(1)", why doesn't it just use the number itself? 

Monger does not modify numerical types. Number literals are longs (or doubles) in Clojure.

What "just the number" is, anyway? It has to be of some type on the JVM.

> And how do I opt out of using the java type in the db?

I don't understand what you're trying to opt out from. MongoDB Java driver stores
longs (which Clojure literals compile to) that way, presumably for a reason. 
--
@michaelklishin, github.com/michaelklishin

Ahmad Hammad

unread,
Oct 13, 2014, 12:08:12 PM10/13/14
to clojure...@googlegroups.com, ah...@buttercloud.com


On Monday, October 13, 2014 5:01:09 PM UTC+1, Michael Klishin wrote:


On 13 October 2014 at 19:55:37, Ahmad Hammad (ah...@buttercloud.com) wrote:
> > I this function works without the :return-new map, however  
> with it I get ""No value supplied for key: {:return-new true}":  
>  
> (defn get-next-sequence [project-key]
> (mc/find-and-modify "projects"
> {:key project-key}
> {$inc {:seq 1}}
> {:return-new true}))
>  
>  
>  
> java.lang.IllegalArgumentException: No value supplied for  
> key: {:return-new true} PersistentHashMap.java:77 clojure.lang.PersistentHashMap.create  
> collection.clj:230 monger.collection/find-and-modify  
> RestFn.java:467 clojure.lang.RestFn.invoke
>  
> based on this (https://github.com/michaelklishin/monger/blob/ef539f48c8c6a880c7c4e0ced2eff7d4631a0cb6/test/monger/test/atomic_modifiers_test.clj#L413)  
> the syntax looks correct.

All monger.collection functions require a connection object to be passed to them as of 2.0:

https://github.com/michaelklishin/monger/blob/master/ChangeLog.md#changes-between-180-and-200

you are not passing it.

I was using an older version and looking at more recent doc, upgrading fixed this, thanks.
 

> Another question, the $inc is updating the attribute with a java  
> "NumberLong(1)", why doesn't it just use the number itself? 

Monger does not modify numerical types. Number literals are longs (or doubles) in Clojure.

What "just the number" is, anyway? It has to be of some type on the JVM.

> And how do I opt out of using the java type in the db?

I don't understand what you're trying to opt out from. MongoDB Java driver stores
longs (which Clojure literals compile to) that way, presumably for a reason. 
 
{
"_id" : ObjectId("543b06f830046c00a3a8855c"),
"seq2" : NumberLong(1),
"seq" : 3,

}

To clarify: seq2 was the result of running findAndModify with $inc from monger, while seq the result of running it in mongo console directly.

I had thought it was causing an issue in the mongo console but later found out that I had a syntax typo somewhere.

All is well, thanks.
 
--  
@michaelklishin, github.com/michaelklishin
Reply all
Reply to author
Forward
0 new messages