我和老婆是怎么才能多加微信好友友要怎么样才能看到她和别人的聊天

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(10990)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'MongoDB的$where查询',
blogAbstract:'有时候,键值对的查询方式并不能满足我们的需求,我们有如下一个集合:',
blogTag:'mongodb使用,mongodb查询',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:5,
publishTime:8,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Convert ObjectID (Mongodb) to String in JavaScript - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.1 million programmers, just like you, helping each other.
J it only takes a minute:
I want to convert ObjectID (Mongodb) to String in JavaScript.
When I get a Object form MongoDB. it like as a object has: timestamp, second, inc, machine.
I can't convert to string.
61.4k50283360
See the doc:
4,68821235
Here is a working example of converting the OjbectId to a string
& a=db.dfgfdgdfg.findOne()
{ "_id" : ObjectId("518cbba25453f9"), "d" : 1 }
& a['_id']
ObjectId("518cbba25453f9")
& a['_id'].toString // This line shows you what the prototype does
function () {
return "ObjectId(" + tojson(this.str) + ")";
& a['_id'].str // Access the property directly
518cbba25453f9
& a['_id'].toString()
ObjectId("518cbba25453f9") // Show the object syntax in sting form
& ""+a['_id']
518cbba25453f9 // Gives the hex string
Did try various other functions like toHexString() with no success.
31.4k554101
Acturally, you can try this:
& a['_id']
ObjectId("518cbba25453f9")
& a['_id'] + ''
"518cbba25453f9"
ObjectId object + String will convert to String object.
Assuming the OP wants to get the hexadecimal string value of the ObjectId, using Mongo 2.2 or above, the valueOf() method returns the representation of the object as a hexadecimal string. This is also achieved with the str property.
The link on anubiskong's post gives all the details, the danger here is to use a technique which has changed from older versions e.g. toString().
ObjectId("507f191e810c1ea").str
objectId.toHexString()
If someone use in Meteorjs, can try:
In server: ObjectId(507f191e810c1ea)._str.
In template: {{ collectionItem._id._str }}.
Just use this : _id.$oid
And you get the ObjectId string. This come with the object.
this works, You have mongodb object: ObjectId(507f191e810c1ea),
to get string value of _id, you just say
ObjectId(507f191e810c1ea).valueOf();
Use this simple trick, your-object.$id
I am getting an array of mongo Ids, here is what I did.
success: function (res) {
console.log('without json res',res);
//without json res {"success":true,"message":" Record updated.","content":[{"$id":"58f04338ffba"},{"$id":"58f04338ffbb"}],"dbResponse":"ok"}
var obj = $.parseJSON(res);
if(obj.content !==null){
$.each(obj.content, function(i,v){
console.log('Id==&', v.$id);
3,029113769
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25841
Stack Overflow works best with JavaScript enabled数据库(41)
& 继上一篇《MongoDB初窥》之后,想必大家对自动生成的主键objectId有所好奇,为什么会是一个24位的字符串。今天,就对objectId的生成原理做一次比较深入的挖掘。
一、 ObjectId的组成
首先通过终端命令行,向mongodb的collection中插入一条不带“_id”的记录。然后,通过查询刚插入的数据,发现自动生成了一个objectId,4e7020cb7cac81af7136236b。具体操作如图1所示。
图1 插入/查询数据
“4e7020cb7cac81af7136236b”这个24位的字符串,虽然看起来很长,也很难理解,但实际上它是由一组十六进制的字符构成,每个字节两位的十六进制数字,总共用了12字节的存储空间。相比MYSQL int类型的4个字节,MongoDB确实多出了很多字节。不过按照现在的存储设备,多出来的字节应该不会成为什么瓶颈。不过MongoDB的这种设计,体现着空间换时间的思想。官网中对ObjectId的规范,如图2所示。
图2 官网对ObjectId的规范
&!--[if !supportLists]--&1) &!--[endif]--&Time
时间戳。将刚才生成的objectid的前4位进行提取“4e7020cb”,然后按照十六进制转为十进制,变为“”,这个数字就是一个时间戳。通过时间戳的转换,就成了易看清的时间格式,如图3所示。
图3 时间戳的转换
&!--[if !supportLists]--&2) &!--[endif]--&Machine
机器。接下来的三个字节就是“7cac81”,这三个字节是所在主机的唯一标识符,一般是机器主机名的散列值,这样就确保了不同主机生成不同的机器hash值,确保在分布式中不造成冲突,这也就是在同一台机器生成的objectId中间的字符串都是一模一样的原因。
&!--[if !supportLists]--&3) &!--[endif]--&PID
进程ID。上面的Machine是为了确保在不同机器产生的objectId不冲突,而pid就是为了在同一台机器不同的mongodb进程产生了objectId不冲突,接下来的“af71”两位就是产生objectId的进程标识符。
&!--[if !supportLists]--&4) &!--[endif]--&INC
自增计数器。前面的九个字节是保证了一秒内不同机器不同进程生成objectId不冲突,这后面的三个字节“36236b”是一个自动增加的计数器,用来确保在同一秒内产生的objectId也不会发现冲突,允许256的3次方等于条记录的唯一性。
总的来看,objectId的前4个字节时间戳,记录了文档创建的时间;接下来3个字节代表了所在主机的唯一标识符,确定了不同主机间产生不同的objectId;后2个字节的进程id,决定了在同一台机器下,不同mongodb进程产生不同的objectId;最后通过3个字节的自增计数器,确保同一秒内产生objectId的唯一性。ObjectId的这个主键生成策略,很好地解决了在分布式环境下高并发情况主键唯一性问题,值得学习借鉴。
&!--[if !supportLists]--&二、 &!--[endif]--&源码分析
MongoDB可以通过自身的服务来产生objectId,也可以通过客户端的驱动程序来生成objectId。虽然objectId是轻量级的,但如果全部在服务端生成肯定会花费一点开销。所以,能从服务器端转移到客户端驱动程序完成的,就尽量转移到客户端来完成,减少服务器端的开销。我们来看一下,客户端的驱动程序是如何来生成objectId的。
&!--[if !supportLists]--&1、下载mongodb java driver源码。 ()
&!--[if !supportLists]--&2、分析ObjectId.java
驱动源码的org.bson包下找到ObjectId.java,进行分析。默认构建的objectId代码如下代码所示,objectId主要由_time,_machine和_inc组成
构建objectId&
public class ObjectId implements Comparable&ObjectId& , java.io.Serializable {
final int _
& & final int _
& & final int _
public ObjectId(){
& & & & _time = (int) (System.currentTimeMillis() / 1000);
& & & & _machine = _
& & & & _inc = _nextInc.getAndIncrement();
& & & & _new =
直接由System.currentTimeMillis()/1000计算得出的时间戳。
&!--[if !supportLists]--&2) &!--[endif]--&_machine
由机器码(machinePiece)和进程码(processPiece)组成,如代码所示。它这里组成方式是:首先,通过NetworkInterface这个类,获取机器的所有网络接口信息(如图4所示),并将得到的字符串取散列值,就得到了机器码;然后通过RuntimeMXBean.getName()方法获取pid,再拼装classloaderid,得到进程码;最后将机器码和进程码进行位或运算得到_machine。不过这里生成的_machine是十进制的,需转成十六进制。
图4 本地调试时的网络接口部分信息
机器码和进程码的生成
private static final int _
final int machineP
StringBuilder sb = new StringBuilder();
& & & & & & Enumeration&NetworkInterface& e = NetworkInterface.getNetworkInterfaces();
& & & & & & while ( e.hasMoreElements() ){
& & & & & & & & NetworkInterface ni = e.nextElement();
& & & & & & & & sb.append( ni.toString() );
& & & & & & }
& & & & & & machinePiece = sb.toString().hashCode() && 16;
& & & & & & LOGGER.fine( &machine piece post: & + Integer.toHexString( machinePiece ) );
final int processP
& & & & & & int processId = new java.util.Random().nextInt();
& & & & & & try {
processId = java.lang.management.ManagementFactory.getRuntimeMXBean().getName().hashCode();
}catch ( Throwable t ){
ClassLoader loader = ObjectId.class.getClassLoader();
& & & & & & int loaderId = loader != null ? System.identityHashCode(loader) : 0;
StringBuilder sb = new StringBuilder();
& & & & & & sb.append(Integer.toHexString(processId));
& & & & & & sb.append(Integer.toHexString(loaderId));
& & & & & & processPiece = sb.toString().hashCode() & 0xFFFF;
& & & & & & LOGGER.fine( &process piece: & + Integer.toHexString( processPiece ) );
_genmachine = machinePiece | processP
& & & & LOGGER.fine( &machine : & + Integer.toHexString( _genmachine ) );
& & }catch ( java.io.IOException ioe ){
& & & & throw new RuntimeException( ioe );
&!--[if !supportLists]--&3) &!--[endif]--&_inc
自增数是通过AtomicInteger的getAndIncrement()方法获取,它能保证每次得到的值是一个递增并不重复的值。
&!--[if !supportLists]--&三、 &!--[endif]--&更多参考
&!--[if !supportLists]--&1、 &!--[endif]--&
原文地址:/xjk15082/archive//2180792.html
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:149204次
积分:2970
积分:2970
排名:第10474名
原创:146篇
转载:14篇
评论:19条
(1)(1)(17)(14)(14)(8)(1)(2)(1)(1)(1)(1)(2)(4)(8)(26)(22)(9)(4)(8)(12)(1)(1)(1)(1)(1)(1)MongoDB 教程
MongoDB ObjectId
在前面几个章节中我们已经使用了MongoDB 的对象 Id(ObjectId)。
在本章节中,我们将了解的ObjectId的结构。
ObjectId 是一个12字节 BSON
类型数据,有以下格式:
前4个字节表示时间戳
接下来的3个字节是机器标识码
紧接的两个字节由进程id组成(PID)
最后三个字节是随机数。
MongoDB中存储的文档必须有一个"_id"键。这个键的值可以是任何类型的,默认是个ObjectId对象。
在一个集合里面,每个文档都有唯一的"_id"值,来确保集合里面每个文档都能被唯一标识。
MongoDB采用ObjectId,而不是其他比较常规的做法(比如自动增加的主键)的主要原因,因为在多个
服务器上同步自动增加主键值既费力还费时。
创建新的ObjectId
使用以下代码生成新的ObjectId:
&newObjectId = ObjectId()
上面的语句返回以下唯一生成的id:
ObjectId("5349b4ddd90f3")
你也可以使用生成的id来取代MongoDB自动生成的ObjectId:
&myObjectId = ObjectId("5349b4ddd90f4")
创建文档的时间戳
由于 ObjectId 中存储了 4 个字节的时间戳,所以你不需要为你的文档保存时间戳字段,你可以通过 getTimestamp
函数来获取文档的创建时间:
&ObjectId("5349b4ddd90f4").getTimestamp()
以上代码将返回 ISO 格式的文档创建时间:
ISODate("T21:49:17Z")
ObjectId 转换为字符串
在某些情况下,您可能需要将ObjectId转换为字符串格式。你可以使用下面的代码:
&new ObjectId().str
以上代码将返回Guid格式的字符串::
5349b4ddd90f3
反馈内容(*必填)
截图标记颜色
联系方式(邮箱)
联系邮箱:
投稿页面:
记住登录状态
重复输入密码mongodb与sql在查询上的区别_性能与架构_传送门
你是真实用户吗(Are you a robot)?
我们怀疑你不是真实用户,已对你的访问做了限制。如果您是真实用户,非常抱歉我们的误判对您造成的影响,您可以通过QQ()或电子邮件()反馈给我们,并在邮件和QQ请求信息里注明您的IP地址:220.177.198.53,我们会尽快恢复您的正常访问权限。另外,如果您不是在访问的当前页面,我们建议您移步
或者 在浏览器中输入以下地址:http://chuansong.me/n/ 访问,您所访问的网站是从抓取的数据,请直接访问,会有更好的体验和更及时的更新。We suspect you are a robot.We are really sorry if you are not,and you can email us () with your current IP address: 220.177.198.53 to get full access to .If you are not accessing
for the current page,you'd better visit
for better performance,as the current website you are accessing is just spam.
觉得不错,分享给更多人看到
性能与架构 微信二维码
分享这篇文章
性能与架构 最新头条文章
性能与架构 热门头条文章}

我要回帖

更多关于 打开微信才能收到消息 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信