mongodb保存长整型的问题

最近用php往mongodb里面写数据的时候出现了一点小问题。就是毫秒级的时间戳保存到mongodb里面后数字被截断了。
例如:1439539213873保存后在mongo里显示为:725169713,这个不是我们想要的结果。

php代码:

$mongo = new MongoClient('mongodb://127.0.0.1:27017');
$db = $mongo->selectCollection("local", "test_data");
$data['num'] = 1439539213873;
$res = $db->insert($data);

mongo里结果:

> db.test_data.find();
{ "_id" : ObjectId("56b3036931a08a07628b4567"), "num" : 725169713 }
> 

 

解决方案:

1.查看php中mongo扩展的配置mongo.native_long,如果是0那在php.ini配置里面改为1;

2.对长整型的数字进行转换

$mongo = new MongoClient('mongodb://127.0.0.1:27017');
$db = $mongo->selectCollection("local", "test_data");
//$data['num'] = 1439539213873;
$data['num'] = new MongoInt64('1439539213873');//进行转换
$res = $db->insert($data);

mongo里结果:

> db.test_data.find();
{ "_id" : ObjectId("56b306c431a08ac80f8b4567"), "num" : NumberLong("1439539213873") }
> 

这样长的整型数字就不会被截断了。

293 Responses

  1. magnificent points altogether, you just received a logo new reader.
    What would you recommend in regards to your post that you
    made a few days in the past? Any positive?

  2. Hello are using WordPress for your blog platform? I’m new to the blog world but I’m
    trying to get started and set up my own. Do you require any coding knowledge to make
    your own blog? Any help would be greatly appreciated!

  3. If some one needs expert view concerning running a
    blog after that i recommend him/her to pay a visit this blog, Keep
    up the pleasant job.

  4. Attractive section of content. I just stumbled upon your
    blog and in accession capital to assert that I acquire in fact enjoyed account your blog
    posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.

  5. Wonderful items from you, man. I’ve remember your stuff prior to and you are simply too magnificent.
    I actually like what you have acquired here, really like what you’re saying and the way in which through
    which you are saying it. You’re making it enjoyable
    and you continue to take care of to stay it sensible.

    I can not wait to read much more from you. That is actually a terrific web site.

  6. Howdy! I could have sworn I’ve been to this site before but after
    checking through some of the post I realized it’s
    new to me. Nonetheless, I’m definitely delighted I found it and I’ll be
    book-marking and checking back often!

  7. obviously like your website however you need to test the spelling on quite a few of your posts.
    A number of them are rife with spelling problems and I to find it very bothersome
    to tell the truth nevertheless I’ll surely come back again.

  8. An outstanding share! I have just forwarded this onto
    a co-worker who had been conducting a little homework on this.

    And he in fact bought me lunch simply because I stumbled
    upon it for him… lol. So allow me to reword this….
    Thanks for the meal!! But yeah, thanks for spending the time to discuss this matter here on your web page.

  9. I know this if off topic but I’m looking into starting my own weblog and was curious what all
    is required to get setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive. Any
    recommendations or advice would be greatly appreciated.

    Many thanks

  10. Hey there superb blog! Does running a blog such as this take a massive amount work?
    I have very little expertise in coding but I was
    hoping to start my own blog in the near future.
    Anyway, if you have any ideas or techniques for new blog owners please share.
    I know this is off topic nevertheless I just needed to ask.
    Appreciate it!

  11. What’s Happening i’m new to this, I stumbled upon this I
    have discovered It absolutely useful and it has helped me out loads.

    I am hoping to give a contribution & assist different users like its aided me.
    Great job.

  12. Hello there, just became alert to your blog through Google, and found
    that it is really informative. I’m going to watch out for brussels.
    I will appreciate if you continue this in future.
    Numerous people will be benefited from your writing.
    Cheers!

  13. I’ve been surfing online more than three hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did,
    the internet will be much more useful than ever before.

  14. Thanks on your marvelous posting! I actually enjoyed reading
    it, you may be a great author. I will be sure to bookmark your
    blog and definitely will come back in the foreseeable future.
    I want to encourage one to continue your great job, have a nice day!

  15. Oh my goodness! Amazing article dude! Thank you so much, However I
    am experiencing difficulties with your RSS. I don’t understand the reason why I can’t subscribe to it.
    Is there anyone else getting the same RSS issues?
    Anyone that knows the answer can you kindly respond?
    Thanx!!

  16. Hi! I could have sworn I’ve been to this website before but after browsing through some
    of the post I realized it’s new to me. Nonetheless,
    I’m definitely happy I found it and I’ll be book-marking and checking back often!

  17. Wonderful goods from you, man. I’ve understand your stuff previous
    to and you are just too fantastic. I really like what you’ve acquired here, really
    like what you are stating and the way in which you say it.

    You make it entertaining and you still care for to keep it smart.
    I can’t wait to read far more from you. This is really a tremendous web site.

  18. Hello There. I found your weblog the usage of msn. That is a very well written article.
    I’ll be sure to bookmark it and come back to read extra of your helpful
    info. Thanks for the post. I’ll definitely return.

  19. An intriguing discussion is worth comment. I do believe that you need to write more on this issue,
    it may not be a taboo subject but usually people do not discuss
    such issues. To the next! Best wishes!!

  20. Howdy very nice blog!! Guy .. Excellent ..
    Amazing .. I will bookmark your website and take the feeds additionally?

    I am satisfied to find so many useful info here within the put up, we’d like develop more strategies
    on this regard, thanks for sharing. . . . . .

  21. Somebody necessarily help to make significantly
    posts I might state. This is the first time I frequented your website page
    and thus far? I amazed with the research you made to make this
    particular publish extraordinary. Wonderful activity!

  22. Right here is the perfect site for anyone who really wants to find out about this topic.

    You realize so much its almost hard to argue with you (not that
    I personally would want to…HaHa). You certainly put a
    brand new spin on a subject that’s been discussed
    for many years. Wonderful stuff, just great!

  23. I really love your blog.. Great colors & theme. Did you make this site yourself?
    Please reply back as I’m planning to create my own personal website and want to learn where you got this from or what the theme is named.
    Appreciate it!

  24. This is very interesting, You are a very skilled blogger.
    I’ve joined your rss feed and look forward to
    seeking more of your wonderful post. Also, I’ve shared your site in my social
    networks!

  25. What i do not realize is in reality how you’re not really much
    more neatly-favored than you may be right now. You are so intelligent.
    You recognize therefore considerably with regards to this matter,
    made me in my view consider it from numerous numerous angles.
    Its like women and men aren’t involved except it’s something to accomplish with Lady
    gaga! Your own stuffs excellent. All the time care for it up!

  26. Hello just wanted to give you a quick heads up and let you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers
    and both show the same outcome.

  27. I’m extremely impressed with your writing skills and also with the layout on your weblog.
    Is this a paid theme or did you modify it yourself?
    Either way keep up the excellent quality writing, it is rare to see a great blog like this one these days.

  28. Amazing issues here. I am very happy to see your article.
    Thank you so much and I’m having a look forward to touch you.
    Will you please drop me a mail?

  29. Hey there, You have done an excellent job. I will certainly digg it and personally suggest to my friends.
    I’m sure they’ll be benefited from this site.

  30. Heya i am for the first time here. I found this board and I find It truly useful &
    it helped me out much. I hope to give something back and aid others like you aided me.

  31. Hello There. I found your blog using msn. This is a really well written article.
    I’ll make sure to bookmark it and return to read more of your useful information.
    Thanks for the post. I’ll certainly return.

  32. Thank you for any other informative web site. The place else could I am getting that type of info written in such
    a perfect means? I have a undertaking that I’m just now working on, and I’ve been at the glance out for such
    information.

  33. Hello, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam feedback?
    If so how do you reduce it, any plugin or anything you can suggest?
    I get so much lately it’s driving me insane so any help is very
    much appreciated.

  34. Hello there! This post could not be written any
    better! Reading through this post reminds me of my
    old room mate! He always kept chatting about this. I
    will forward this article to him. Fairly certain he will have a good read.
    Thanks for sharing!

  35. I simply couldn’t depart your website before suggesting that I actually loved the standard info a
    person provide to your visitors? Is gonna be again incessantly
    in order to check out new posts

  36. Does your site have a contact page? I’m having trouble locating it but, I’d
    like to shoot you an e-mail. I’ve got some suggestions for
    your blog you might be interested in hearing. Either way, great site
    and I look forward to seeing it grow over time.

  37. Thanks for another informative website. The place else may I am getting that type
    of info written in such a perfect method? I have a venture
    that I am just now working on, and I’ve been at the look out for such information.

  38. My developer is trying to persuade me to move to .net
    from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am concerned about switching
    to another platform. I have heard excellent things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?
    Any help would be greatly appreciated!

  39. I must thank you for the efforts you have put in writing this
    blog. I am hoping to check out the same high-grade blog posts by you later
    on as well. In truth, your creative writing abilities has inspired me to
    get my own website now 😉

  40. Hey I know this is off topic but I was wondering if you knew of any widgets I could add
    to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some
    experience with something like this. Please let
    me know if you run into anything. I truly enjoy reading your blog and I look
    forward to your new updates.

  41. What i don’t understood is in truth how you are not really a lot more
    neatly-preferred than you may be now. You are very intelligent.

    You recognize thus significantly in the case of this matter, made me for
    my part consider it from numerous varied angles. Its like women and
    men aren’t involved unless it’s something to do with Woman gaga!

    Your personal stuffs nice. Always deal with it
    up!

  42. I抎 must check with you here. Which is not something I normally do! I get pleasure from reading a put up that will make folks think. Also, thanks for allowing me to remark!

  43. Hi there to every one, the contents present at this website are truly amazing for people experience, well,
    keep up the good work fellows. pof natalielise

  44. Hey I am so delighted I found your weblog, I really found you
    by accident, while I was researching on Yahoo for something
    else, Anyways I am here now and would just like to say many thanks for a remarkable post and a
    all round exciting blog (I also love the theme/design),
    I don’t have time to read through it all at the moment but
    I have book-marked it and also added your RSS feeds, so when I have time I will
    be back to read a great deal more, Please do keep up the great b.

  45. With havin so much content and articles do you ever run into any problems of plagorism or copyright infringement?

    My blog has a lot of unique content I’ve either authored myself or outsourced
    but it seems a lot of it is popping it up all over the internet without my agreement.
    Do you know any methods to help prevent content from being stolen? I’d definitely appreciate
    it.

  46. Hi would you mind sharing which blog platform you’re working with?
    I’m looking to start my own blog soon but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and
    style seems different then most blogs and I’m looking for something
    completely unique. P.S Apologies for being off-topic but I
    had to ask!

  47. Hello! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing many months of hard
    work due to no back up. Do you have any solutions to stop hackers?

  48. Unquestionably believe that which you said. Your favourite reason seemed to be at the
    internet the easiest factor to be mindful of.
    I say to you, I certainly get annoyed whilst other people consider issues that they plainly do not recognize about.
    You managed to hit the nail upon the top as well as defined out the entire thing without having side-effects , people can take a
    signal. Will probably be again to get more. Thank you

  49. First off I want to say great blog! I had a quick question which I’d like to ask if you do not mind.

    I was curious to know how you center yourself and clear your mind prior to writing.

    I’ve had difficulty clearing my mind in getting my
    ideas out there. I truly do enjoy writing however it just seems like the first 10
    to 15 minutes are generally wasted just trying to
    figure out how to begin. Any recommendations or tips?
    Many thanks!

发表评论

电子邮件地址不会被公开。 必填项已用*标注