0

在本地工作时,我可以通过调用以下方式测试我的应用程序:

http://localhost:9000/r/123

方法:

def showSurvey(id: String) = Action {

      implicit val reader = Review.ReviewReader
    Async {
      val cursor = reviews.find(BSONDocument("_id" -> BSONObjectID(id))).cursor[Review]
      cursor.headOption.map(maybeReview =>
        maybeReview.map(review => {
          // fill form
          Ok(views.html.review.desktopSurvey(Some(id), surveyForm.fill(SurveyForm(review.grade, review.text, REGULAR_AUTH, false, "", "")), grades))
        }


        ).getOrElse {
          //NotFound Temporary below:
      val review = Review(Some(new BSONObjectID(id)), 3, "bla", Some(new DateTime()), Some(new DateTime()), Some("0.0.0.0"), ReviewStatus.NOT_CLAIMED, Some(1), Some(1L))
      Ok(views.html.review.desktopSurvey(Some(id), surveyForm.fill(SurveyForm(review.grade, review.text, REGULAR_AUTH, false, "", "")), grades))
     }
      ).recover {
        case e => InternalServerError(e.getMessage())
      }
    }
  }

但是当在生产中运行应用程序时clean compile stage,然后转到我得到的 url:

[error] r.c.a.MongoDBSystem - The entire node set is unreachable, is there a network problem?

我觉得这很奇怪,因为插件似乎工作正常:

[info] application - ReactiveMongoPlugin successfully started with db 'blala'! Servers:
        [87.238.57.140:27017]
4

1 回答 1

0

通过检查 mongodb 日志,我发现连接正常,但发送的 bson 无效:

Tue May 21 11:18:11.257 [conn531] Assertion: 10307:Client Error: bad object in message: invalid bson
0xdcf361 0xd90a1b 0xd90f5c 0x75b289 0x75b3fb 0x9f4367 0x9f57e2 0x6e747a 0xdbbb7e 0x7fa22e96d9ca 0x7fa22dd14cdd 
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xdcf361]
 /usr/bin/mongod(_ZN5mongo11msgassertedEiPKc+0x9b) [0xd90a1b]
 /usr/bin/mongod() [0xd90f5c]
 /usr/bin/mongod(_ZN5mongo9DbMessage9nextJsObjEv+0x249) [0x75b289]
 /usr/bin/mongod(_ZN5mongo12QueryMessageC1ERNS_9DbMessageE+0x8b) [0x75b3fb]
 /usr/bin/mongod() [0x9f4367]
 /usr/bin/mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0x392) [0x9f57e2]
 /usr/bin/mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0x9a) [0x6e747a]
 /usr/bin/mongod(_ZN5mongo17PortMessageServer17handleIncomingMsgEPv+0x42e) [0xdbbb7e]
 /lib/libpthread.so.0(+0x69ca) [0x7fa22e96d9ca]
 /lib/libc.so.6(clone+0x6d) [0x7fa22dd14cdd]
Tue May 21 11:18:11.261 [conn531] AssertionException handling request, closing client connection: 10307 Client Error: bad object in message: invalid bson

这让我查看了代码,问题是我发送了一个无效的 ObjectId,在我的例子中是123。不知何故,这个错误被我的应用程序吞噬了。因此,当发送的 ObjectId 可能已损坏时,请检查:

val maybeOID: Try[BSONObjectID] = BSONObjectID.parse(id)
if (maybeOID.isSuccess) {
    // Do stuff
}
于 2013-05-21T09:56:27.667 回答