2015年1月26日 星期一

[MongoDB] When name goes wrong

db.collectionName.find()

> work

db.collectionName.renameCollection("1")

> operation ok

db.1.find()

> error, illegal collection name




How to rollback?

db.getCollection("1").find()

> work

db.getCollection("1").renameCollection("properCollectionName")

> done



http://blog.onetechnical.com/2013/05/22/how-to-drop-a-mongodb-collection-with-an-illegal-name/

2015年1月22日 星期四

[Java Groovy] Convert Array or Object to String

def numbers = [0, 1, 2, 3, 4, 5] as Integer[]
assert '0 x 1 x 2 x 3 x 4 x 5' == numbers.join(' x ')

def objects = [new URL('http://www.mrhaki.com'), 'mrhaki', new Expando(name: 'mrhaki'), new Date(109, 10, 10)]
assert 'http://www.mrhaki.com,mrhaki,{name=mrhaki},Tue Nov 10 00:00:00 UTC 2009' == objects.join(',')

http://mrhaki.blogspot.hk/2009/10/groovy-goodness-join-elements-to-string.html

2015年1月14日 星期三

[Spring] [MongoDB] MongoDB Collection Event Listener

Event Listeners:

  • onBeforeConvert(E document)
  • onAfterConvert(DbObject dbo, E document)
  • onBeforeSave(E document)
  • onAfterSave( E collection, DbObject dbo)
  • ...

How to Use:

Step 1: Write Java class

Step 2: Register Event Listener in Spring XML



http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/

http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/

http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html

[MongoDB] ObjectId to Timestamp Converter

Test data (ObjectId): 54b37110f441a40ce4239497

Return (ISO Timestamp): 2015-01-12T07:00:32.000Z

* Note that _id stores the timestamp to second only, no millisecond value stored :(

http://steveridout.github.io/mongo-object-time/

[JPA] @transient

transient : passing with time; remaining in a place only a brief of time
http://www.thefreedictionary.com/transient

@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation

2015年1月13日 星期二

Weight Loss! The journey continues

是一個漫長的奮鬥旅程…… 最近嘗試努力改變的生活習慣: 晚上九時半去瞓覺 瞓覺前唔用電子奶咀,即喺ipad同手提電話(因為呢家部電話用耐咗,會無電要叉過夜) 用蔬果代替日常零食,例子有:車厘茄、藍莓、士多啤梨、粟米芯、提子,都係細細地嘅一舊一舊comp食啲 唔食熱氣零食 安靜去每...